Changeset 181a6af for src/Common
- Timestamp:
- Mar 20, 2019, 1:53:02 PM (5 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PersistentMap.h
r42f1279c r181a6af 114 114 } 115 115 116 /// check if this is the only reference to itself117 /// NOTE: optimizations employing this function are not thread-safe118 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_count120 return (this->shared_from_this().use_count() - local_ptrs) > 2;121 }122 123 116 public: 124 117 using key_type = typename Base::key_type; … … 154 147 // remove map from base 155 148 Base base_map = base->take_as<Base>(); 149 base->reset_as_base(); 156 150 157 151 // switch base to inverse of self and mutate base map … … 161 155 auto it = base_map.find( self.key ); 162 156 163 if ( base->is_shared( 1 ) ) { 164 base->reset_as_base(); 165 base->init<Ins>( 157 base->init<Ins>( 166 158 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 167 base->mode = INS; 168 } 159 base->mode = INS; 169 160 170 161 base_map.erase( it ); … … 174 165 Ins& self = mut_this->as<Ins>(); 175 166 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; 181 169 182 170 base_map.emplace( std::move(self.key), std::move(self.val) ); … … 187 175 auto it = base_map.find( self.key ); 188 176 189 if ( base->is_shared( 1 ) ) { 190 base->reset_as_base(); 191 base->init<Ins>( 177 base->init<Ins>( 192 178 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 193 base->mode = UPD; 194 } 179 base->mode = UPD; 195 180 196 181 it->second = std::move(self.val); … … 257 242 // transfer map to new node 258 243 Ptr ret = std::make_shared<Self>( take_as<Base>() ); 244 reset_as_base(); 259 245 Base& base_map = ret->as<Base>(); 260 246 … … 262 248 auto it = base_map.find( k ); 263 249 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; 270 253 271 254 base_map.emplace_hint( it, std::forward<K>(k), std::forward<V>(v) ); 272 255 } 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; 279 259 280 260 it->second = std::forward<V>(v); … … 293 273 // transfer map to new node 294 274 Ptr ret = std::make_shared<Self>( take_as<Base>() ); 275 reset_as_base(); 295 276 Base& base_map = ret->as<Base>(); 296 277 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; 303 281 304 282 base_map.erase( k );
Note: See TracChangeset
for help on using the changeset viewer.