Changeset 181a6af


Ignore:
Timestamp:
Mar 20, 2019, 1:53:02 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
114bde6
Parents:
42f1279c
Message:

Walk back history changes to persistent map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PersistentMap.h

    r42f1279c r181a6af  
    114114        }
    115115
    116         /// check if this is the only reference to itself
    117         /// NOTE: optimizations employing this function are not thread-safe
    118         bool is_shared(long local_ptrs = 0) const {
    119                 // 2 accounts for both the pointer which owns "this" and the one created for its use_count
    120                 return (this->shared_from_this().use_count() - local_ptrs) > 2;
    121         }
    122 
    123116public:
    124117        using key_type = typename Base::key_type;
     
    154147                // remove map from base
    155148                Base base_map = base->take_as<Base>();
     149                base->reset_as_base();
    156150
    157151                // switch base to inverse of self and mutate base map
     
    161155                                auto it = base_map.find( self.key );
    162156
    163                                 if ( base->is_shared( 1 ) ) {
    164                                         base->reset_as_base();
    165                                         base->init<Ins>(
     157                                base->init<Ins>(
    166158                                                mut_this->shared_from_this(), std::move(self.key), std::move(it->second) );
    167                                         base->mode = INS;
    168                                 }
     159                                base->mode = INS;
    169160
    170161                                base_map.erase( it );
     
    174165                                Ins& self = mut_this->as<Ins>();
    175166
    176                                 if ( base->is_shared( 1 ) ) {
    177                                         base->reset_as_base();
    178                                         base->init<Rem>( mut_this->shared_from_this(), self.key );
    179                                         base->mode = REM;
    180                                 }
     167                                base->init<Rem>( mut_this->shared_from_this(), self.key );
     168                                base->mode = REM;
    181169
    182170                                base_map.emplace( std::move(self.key), std::move(self.val) );
     
    187175                                auto it = base_map.find( self.key );
    188176
    189                                 if ( base->is_shared( 1 ) ) {
    190                                         base->reset_as_base();
    191                                         base->init<Ins>(
     177                                base->init<Ins>(
    192178                                                mut_this->shared_from_this(), std::move(self.key), std::move(it->second) );
    193                                         base->mode = UPD;
    194                                 }
     179                                base->mode = UPD;
    195180
    196181                                it->second = std::move(self.val);
     
    257242                // transfer map to new node
    258243                Ptr ret = std::make_shared<Self>( take_as<Base>() );
     244                reset_as_base();
    259245                Base& base_map = ret->as<Base>();
    260246
     
    262248                auto it = base_map.find( k );
    263249                if ( it == base_map.end() ) {
    264                         if ( is_shared() ) {
    265                                 // set self to REM node and insert into base
    266                                 reset_as_base();
    267                                 init<Rem>( ret, k );
    268                                 mode = REM;
    269                         }
     250                        // set self to REM node and insert into base
     251                        init<Rem>( ret, k );
     252                        mode = REM;
    270253
    271254                        base_map.emplace_hint( it, std::forward<K>(k), std::forward<V>(v) );
    272255                } else {
    273                         if ( is_shared() ) {
    274                                 // set self to UPD node and modify base
    275                                 reset_as_base();
    276                                 init<Ins>( ret, std::forward<K>(k), std::move(it->second) );
    277                                 mode = UPD;
    278                         }
     256                        // set self to UPD node and modify base
     257                        init<Ins>( ret, std::forward<K>(k), std::move(it->second) );
     258                        mode = UPD;
    279259
    280260                        it->second = std::forward<V>(v);
     
    293273                // transfer map to new node
    294274                Ptr ret = std::make_shared<Self>( take_as<Base>() );
     275                reset_as_base();
    295276                Base& base_map = ret->as<Base>();
    296277
    297                 if ( is_shared() ) {
    298                         // set self to INS node and remove from base
    299                         reset_as_base();
    300                         init<Ins>( ret, k, base_map[k] );
    301                         mode = INS;
    302                 }
     278                // set self to INS node and remove from base
     279                init<Ins>( ret, k, base_map[k] );
     280                mode = INS;
    303281
    304282                base_map.erase( k );
Note: See TracChangeset for help on using the changeset viewer.