Changeset 804bf677
- Timestamp:
- Oct 13, 2021, 9:52:02 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 7b0e8b7
- Parents:
- 4b3b352
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/string_res.cfa
r4b3b352 r804bf677 48 48 static inline void reduce( VbyteHeap &, int ); // reduce the size of the byte area 49 49 50 static inline void ?{}( VbyteHeap &, int = 1000 );50 static inline void ?{}( VbyteHeap &, size_t = 1000 ); 51 51 static inline void ^?{}( VbyteHeap & ); 52 52 static inline void ByteCopy( char *, int, int, char *, int, int ); // copy a block of bytes from one location in the heap to another … … 62 62 // Allocate the storage for the variable sized area and intialize the heap variables. 63 63 64 static inline void ?{}( VbyteHeap & this, int Size ) with(this) {64 static inline void ?{}( VbyteHeap & this, size_t Size ) with(this) { 65 65 #ifdef VbyteDebug 66 66 serr | "enter:VbyteHeap::VbyteHeap, this:" | &this | " Size:" | Size; … … 149 149 (older){ ambient_string_sharectx }; 150 150 if ( mode == NEW_SHARING ) { 151 (activeHeap){ new( 1000 ) };151 (activeHeap){ new( (size_t) 1000 ) }; 152 152 } else { 153 153 verify( mode == NO_SHARING ); … … 217 217 // Empty constructor 218 218 void ?{}(string_res &s) with(s) { 219 assert( ambient_string_sharectx->activeHeap && "Need to implement private contexts" ); 220 (Handle){ * ambient_string_sharectx->activeHeap }; 219 if( ambient_string_sharectx->activeHeap ) { 220 (Handle){ * ambient_string_sharectx->activeHeap }; 221 (shareEditSet_owns_ulink){ false }; 222 } else { 223 (Handle){ * new( (size_t) 10 ) }; // TODO: can I lazily avoid allocating for empty string 224 (shareEditSet_owns_ulink){ true }; 225 } 221 226 s.shareEditSet_prev = &s; 222 227 s.shareEditSet_next = &s; … … 224 229 225 230 static inline void eagerCopyCtorHelper(string_res &s, const char* rhs, size_t rhslnth) with(s) { 226 assert( ambient_string_sharectx->activeHeap && "Need to implement private contexts" ); 227 (Handle){ * ambient_string_sharectx->activeHeap }; 231 if( ambient_string_sharectx->activeHeap ) { 232 (Handle){ * ambient_string_sharectx->activeHeap }; 233 (shareEditSet_owns_ulink){ false }; 234 } else { 235 (Handle){ * new( rhslnth ) }; 236 (shareEditSet_owns_ulink){ true }; 237 } 228 238 Handle.s = VbyteAlloc(*Handle.ulink, rhslnth); 229 239 Handle.lnth = rhslnth; … … 248 258 void ?{}(string_res &s, const string_res & s2, StrResInitMode mode, size_t start, size_t end ) { 249 259 250 assert( ambient_string_sharectx->activeHeap && "Need to implement private contexts" );251 252 260 verify( start <= end && end <= s2.Handle.lnth ); 253 261 … … 258 266 s.Handle.lnth = end - start; 259 267 s.Handle.ulink = ambient_string_sharectx->activeHeap; 268 (s.shareEditSet_owns_ulink){ false }; 260 269 AddThisAfter(s.Handle, s2.Handle ); // insert this handle after rhs handle 261 270 // ^ bug? skip others at early point in string … … 396 405 Handle.s = VbyteAlloc(*Handle.ulink, rhslnth); 397 406 Handle.lnth = rhslnth; 407 (s.shareEditSet_owns_ulink){ false }; 398 408 for ( int i = 0; i < rhslnth; i += 1 ) { // copy characters 399 409 Handle.s[i] = rhs[i]; … … 464 474 // s.shareEditSet_next = &s; 465 475 // s.shareEditSet_prev = &s; 476 477 if (shareEditSet_owns_ulink && s.shareEditSet_next == &s) { // last one out 478 delete( s.Handle.ulink ); 479 } 466 480 } 467 481 -
libcfa/src/containers/string_res.hfa
r4b3b352 r804bf677 43 43 struct string_res { 44 44 HandleNode Handle; // chars, start, end, global neighbours 45 bool shareEditSet_owns_ulink; 45 46 string_res * shareEditSet_prev; 46 47 string_res * shareEditSet_next; -
tests/collections/.expect/string-ctx-manage.txt
r4b3b352 r804bf677 3 3 hi 4 4 bye 5 hi 5 6 done -
tests/collections/string-ctx-manage.cfa
r4b3b352 r804bf677 24 24 sout | y; // hi 25 25 26 x = "bye"; //.... Bookmark 9/30 shallow: surprisingly this step failed26 x = "bye"; 27 27 y = x; // y was already in different context => eager copy 28 28 assert( y.inner->Handle.s != x.inner->Handle.s); … … 30 30 } 31 31 32 void failSoloAlloc() {32 void soloAlloc() { 33 33 string x = "hi"; 34 34 string_sharectx c = { NO_SHARING }; 35 36 string y = x; // y allocates into private pad, implying eager copy 37 assert( y.inner->Handle.s != x.inner->Handle.s); 38 sout | y; // hi 35 39 36 // want: allocation into private pad, with forced eager copy into it 37 // got: assertion failure, "Need to implement private contexts" 38 string y = x; 40 // -- following hits "need to implement actual growth" 41 // and it passes if I modify string_res.cfa to oversize the owned heaps 42 43 // x = "bye"; 44 // y = x; // into private y => eager copy 45 // assert( y.inner->Handle.s != x.inner->Handle.s); 46 // sout | y; // bye 39 47 } 40 48 41 volatile bool showFail = false;42 49 43 50 int main() { 44 51 baseline(); 45 52 eagerCopy(); 46 if (showFail) { 47 failSoloAlloc(); 48 } 53 soloAlloc(); 49 54 printf("done\n"); 50 55 }
Note: See TracChangeset
for help on using the changeset viewer.