|
Boost-Commit : |
From: droba_at_[hidden]
Date: 2008-08-21 10:46:15
Author: pavol_droba
Date: 2008-08-21 10:46:15 EDT (Thu, 21 Aug 2008)
New Revision: 48281
URL: http://svn.boost.org/trac/boost/changeset/48281
Log:
self assignment problem in is_any_ofF fixed
Text files modified:
trunk/boost/algorithm/string/detail/classification.hpp | 56 ++++++++++++++++++++++++++++-----------
trunk/libs/algorithm/string/test/predicate_test.cpp | 1
2 files changed, 41 insertions(+), 16 deletions(-)
Modified: trunk/boost/algorithm/string/detail/classification.hpp
==============================================================================
--- trunk/boost/algorithm/string/detail/classification.hpp (original)
+++ trunk/boost/algorithm/string/detail/classification.hpp 2008-08-21 10:46:15 EDT (Thu, 21 Aug 2008)
@@ -141,9 +141,12 @@
// Assignment
is_any_ofF& operator=(const is_any_ofF& Other)
{
+ // Handle self assignment
+ if(this==&Other) return *this;
+
// Prepare storage
- const set_value_type* SrcStorage=0;
- set_value_type* DestStorage=0;
+ const set_value_type* SrcStorage;
+ set_value_type* DestStorage;
if(use_fixed_storage(Other.m_Size))
{
@@ -162,23 +165,44 @@
}
else
{
- // Use dynamic storage
-
- // Create new buffer
- set_value_type* pTemp=new set_value_type[Other.m_Size];
- DestStorage=pTemp;
+ // Other uses dynamic storage
SrcStorage=Other.m_Storage.m_dynSet;
-
- // Delete old storage if necessary
- if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
+
+ // Check what kind of storage are we using right now
+ if(use_fixed_storage(m_Size))
{
- delete [] m_Storage.m_dynSet;
+ // Using fixed storage, allocate new
+ set_value_type* pTemp=new set_value_type[Other.m_Size];
+ DestStorage=pTemp;
+ m_Storage.m_dynSet=pTemp;
+ m_Size=Other.m_Size;
+ }
+ else
+ {
+ // Using dynamic storage, check if can reuse
+ if(m_Storage.m_dynSet!=0 && m_Size>=Other.m_Size && m_Size<Other.m_Size*2)
+ {
+ // Reuse the current storage
+ DestStorage=m_Storage.m_dynSet;
+ m_Size=Other.m_Size;
+ }
+ else
+ {
+ // Allocate the new one
+ set_value_type* pTemp=new set_value_type[Other.m_Size];
+ DestStorage=pTemp;
+
+ // Delete old storage if necessary
+ if(m_Storage.m_dynSet!=0)
+ {
+ delete [] m_Storage.m_dynSet;
+ }
+ // Store the new storage
+ m_Storage.m_dynSet=pTemp;
+ // Set new size
+ m_Size=Other.m_Size;
+ }
}
-
- // Store the new storage
- m_Storage.m_dynSet=pTemp;
- // Set new size
- m_Size=Other.m_Size;
}
// Copy the data
Modified: trunk/libs/algorithm/string/test/predicate_test.cpp
==============================================================================
--- trunk/libs/algorithm/string/test/predicate_test.cpp (original)
+++ trunk/libs/algorithm/string/test/predicate_test.cpp 2008-08-21 10:46:15 EDT (Thu, 21 Aug 2008)
@@ -102,6 +102,7 @@
// test assignment operator
Pred pred1=pred;
pred1=pred;
+ pred1=pred1;
if(bYes)
{
BOOST_CHECK( all( input, pred ) );
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk