Changeset fdae913
- Timestamp:
- Mar 15, 2019, 3:43:39 PM (6 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:
- 42f1279c
- Parents:
- b419abb
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Common/PersistentMap.h ¶
rb419abb rfdae913 114 114 } 115 115 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 116 123 public: 117 124 using size_type = std::size_t; … … 144 151 // remove map from base 145 152 Base base_map = base->take_as<Base>(); 146 base->reset_as_base();147 // xxx -- investigate checking ref-count and omitting re-initialization if 1148 153 149 154 // switch base to inverse of self and mutate base map … … 153 158 auto it = base_map.find( self.key ); 154 159 155 base->init<Ins>( 156 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 157 base->mode = INS; 160 if ( base->is_shared( 1 ) ) { 161 base->reset_as_base(); 162 base->init<Ins>( 163 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 164 base->mode = INS; 165 } 158 166 159 167 base_map.erase( it ); … … 163 171 Ins& self = mut_this->as<Ins>(); 164 172 165 base->init<Rem>( mut_this->shared_from_this(), self.key ); 166 base->mode = REM; 173 if ( base->is_shared( 1 ) ) { 174 base->reset_as_base(); 175 base->init<Rem>( mut_this->shared_from_this(), self.key ); 176 base->mode = REM; 177 } 167 178 168 179 base_map.emplace( std::move(self.key), std::move(self.val) ); … … 173 184 auto it = base_map.find( self.key ); 174 185 175 base->init<Ins>( 176 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 177 base->mode = UPD; 186 if ( base->is_shared( 1 ) ) { 187 base->reset_as_base(); 188 base->init<Ins>( 189 mut_this->shared_from_this(), std::move(self.key), std::move(it->second) ); 190 base->mode = UPD; 191 } 178 192 179 193 it->second = std::move(self.val); … … 240 254 // transfer map to new node 241 255 Ptr ret = std::make_shared<Self>( take_as<Base>() ); 242 reset_as_base();243 256 Base& base_map = ret->as<Base>(); 244 257 … … 246 259 auto it = base_map.find( k ); 247 260 if ( it == base_map.end() ) { 248 // set self to REM node and insert into base 249 init<Rem>( ret, k ); 250 mode = REM; 261 if ( is_shared() ) { 262 // set self to REM node and insert into base 263 reset_as_base(); 264 init<Rem>( ret, k ); 265 mode = REM; 266 } 251 267 252 268 base_map.emplace_hint( it, std::forward<K>(k), std::forward<V>(v) ); 253 269 } else { 254 // set self to UPD node and modify base 255 init<Ins>( ret, std::forward<K>(k), std::move(it->second) ); 256 mode = UPD; 270 if ( is_shared() ) { 271 // set self to UPD node and modify base 272 reset_as_base(); 273 init<Ins>( ret, std::forward<K>(k), std::move(it->second) ); 274 mode = UPD; 275 } 257 276 258 277 it->second = std::forward<V>(v); … … 271 290 // transfer map to new node 272 291 Ptr ret = std::make_shared<Self>( take_as<Base>() ); 273 reset_as_base();274 292 Base& base_map = ret->as<Base>(); 275 293 276 // set self to INS node and remove from base 277 init<Ins>( ret, k, base_map[k] ); 278 mode = INS; 294 if ( is_shared() ) { 295 // set self to INS node and remove from base 296 reset_as_base(); 297 init<Ins>( ret, k, base_map[k] ); 298 mode = INS; 299 } 279 300 280 301 base_map.erase( k ); -
TabularUnified src/SymTab/Indexer.cc ¶
rb419abb rfdae913 189 189 void Indexer::leaveScope() { 190 190 if ( repScope == scope ) { 191 // replace all maps and scope index with previous scope's versions192 191 Ptr prev = prevScope; // make sure prevScope stays live 193 192 *this = std::move(*prevScope); // replace with previous scope
Note: See TracChangeset
for help on using the changeset viewer.