Fixed container::StripedSet::emplace() bug
authorkhizmax <libcds.dev@gmail.com>
Sat, 26 Mar 2016 14:33:37 +0000 (17:33 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 26 Mar 2016 14:33:37 +0000 (17:33 +0300)
Minor fixes

cds/container/striped_set.h
cds/container/striped_set/adapter.h

index c859da6d8be46d615578997b39fd2c995e12bfd8..e4f4ec78e938fa95d7860df1b58f4d7c6dbc6f65 100644 (file)
@@ -624,13 +624,14 @@ namespace cds { namespace container {
         {
             bool bOk;
             bool bResize;
-            size_t nHash = base_class::hashing( value_type( std::forward<Args>(args)...));
+            value_type val( std::forward<Args>( args )... );
+            size_t nHash = base_class::hashing( val );
             bucket_type * pBucket;
             {
                 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
                 pBucket = base_class::bucket( nHash );
 
-                bOk = pBucket->emplace( std::forward<Args>(args)...);
+                bOk = pBucket->emplace( std::move( val ));
                 bResize = bOk && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
             }
 
@@ -667,7 +668,7 @@ namespace cds { namespace container {
         std::pair<bool, bool> update( Q const& val, Func func, bool bAllowInsert = true )
         {
             std::pair<bool, bool> result;
-            bool bResize;
+            bool bResize = false;
             size_t nHash = base_class::hashing( val );
             bucket_type * pBucket;
             {
@@ -675,7 +676,8 @@ namespace cds { namespace container {
                 pBucket = base_class::bucket( nHash );
 
                 result = pBucket->update( val, func, bAllowInsert );
-                bResize = result.first && result.second && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
+                if ( result.first && result.second )
+                    bResize = base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
             }
 
             if ( bResize )
index f6738022cfe0eaf151ecfdc57963a53679988a4a..bbb1be14652a9ad396f4479dd409c21c471cd119 100644 (file)
@@ -328,7 +328,7 @@ namespace cds { namespace container {
                         return std::make_pair( true, res.second );
                     }
                     else {
-                        auto it = m_Set.find( val );
+                        auto it = m_Set.find( value_type( val ));
                         if ( it == m_Set.end() )
                             return std::make_pair( false, false );
                         func( false, const_cast<value_type&>(*it), val );