Changes in / [893fb47:a9049dd]
- Location:
- libcfa/src/collections
- Files:
-
- 2 edited
-
string_res.cfa (modified) (36 diffs)
-
string_res.hfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/string_res.cfa
r893fb47 ra9049dd 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 25 16:22:58202613 // Update Count : 31612 // Last Modified On : Thu May 7 13:14:45 2026 13 // Update Count : 135 14 14 // 15 15 … … 29 29 //######################### VbyteHeap "header" ######################### 30 30 31 //#define VbyteDebug 32 #ifdef VbyteDebug 33 HandleNode * HeaderPtr; 34 35 void printHandleList( HandleNode & s ) with(s) { 36 printf( "HandleList: Header %p\n", HeaderPtr ); 37 for ( HandleNode * ni = HeaderPtr;; ) { // print header node 38 printf( "\tnode:%p lnth:%u s:%p, \"", ni, ni->lnth, ni->s ); 39 for ( i; ni->lnth ) { 40 printf( "%c", ni->s[i] ); 41 } // for 42 printf( "\" flink:%p blink:%p\n", ni->flink, ni->blink ); 43 ni = ni->flink; 44 if ( ni == HeaderPtr ) break; 45 } // for 46 } 31 #ifdef VbyteDebug 32 HandleNode *HeaderPtr; 47 33 #endif // VbyteDebug 48 34 … … 54 40 int InitSize; // initial number of bytes in the byte-string area 55 41 int CurrSize; // current number of bytes in the byte-string area 56 char * StartVbyte; // pointer to the `st byte of the start of the byte-string area57 char * EndVbyte;// pointer to the next byte after the end of the currently used portion of byte-string area58 void * ExtVbyte;// pointer to the next byte after the end of the byte-string area42 char *StartVbyte; // pointer to the `st byte of the start of the byte-string area 43 char *EndVbyte; // pointer to the next byte after the end of the currently used portion of byte-string area 44 void *ExtVbyte; // pointer to the next byte after the end of the byte-string area 59 45 60 46 HandleNode Header; // header node for handle list … … 76 62 static void AddThisAfter( HandleNode &, HandleNode & ); 77 63 static void DeleteNode( HandleNode & ); 78 static void MoveThisAfter( HandleNode &, HandleNode & ); // move current handle after parameter handle64 static void MoveThisAfter( HandleNode &, const HandleNode & ); // move current handle after parameter handle 79 65 80 66 … … 83 69 static void ?{}( VbyteHeap & s, size_t Size ) with(s) { 84 70 #ifdef VbyteDebug 85 printf( "enter:VbyteHeap::VbyteHeap, s:%p Size:%zd\n", &s, Size );71 serr | "enter:VbyteHeap::VbyteHeap, s:" | &s | " Size:" | Size; 86 72 #endif // VbyteDebug 87 73 NoOfCompactions = NoOfExtensions = NoOfReductions = 0; … … 91 77 Header.flink = Header.blink = &Header; 92 78 Header.ulink = &s; 93 // Should be unnecessary to initialize.94 // Header.s = 0p;95 // Header.lnth = 0;96 79 #ifdef VbyteDebug 97 80 HeaderPtr = &Header; 98 printf( "exit:VbyteHeap::VbyteHeap, s:%p\n", &s );81 serr | "exit:VbyteHeap::VbyteHeap, s:" | &s; 99 82 #endif // VbyteDebug 100 83 } // VbyteHeap … … 116 99 static void ?{}( HandleNode & s ) with(s) { 117 100 #ifdef VbyteDebug 118 printf( "enter:HandleNode::HandleNode, s:%p\n", &s ); 119 #endif // VbyteDebug 120 // Should be unnecessary to initialize. 121 // s = 0p; 122 // lnth = 0; 123 #ifdef VbyteDebug 124 printf( "exit:HandleNode::HandleNode, s:%p\n", &s ); 101 serr | "enter:HandleNode::HandleNode, s:" | &s; 102 #endif // VbyteDebug 103 s = 0; 104 lnth = 0; 105 #ifdef VbyteDebug 106 serr | "exit:HandleNode::HandleNode, s:" | &s; 125 107 #endif // VbyteDebug 126 108 } // HandleNode … … 132 114 static void ?{}( HandleNode & s, VbyteHeap & vh ) with(s) { 133 115 #ifdef VbyteDebug 134 printf( "enter:HandleNode::HandleNode, s:%p\n", &s );116 serr | "enter:HandleNode::HandleNode, s:" | &s; 135 117 #endif // VbyteDebug 136 118 s = 0; … … 139 121 AddThisAfter( s, *vh.Header.blink ); 140 122 #ifdef VbyteDebug 141 printf( "exit:HandleNode::HandleNode, s:%p\n", &s );123 serr | "exit:HandleNode::HandleNode, s:" | &s; 142 124 #endif // VbyteDebug 143 125 } // HandleNode … … 149 131 static void ^?{}( HandleNode & s ) with(s) { 150 132 #ifdef VbyteDebug 151 printf( "enter:HandleNode::~HandleNode, s:%p\n", &s );133 serr | "enter:HandleNode::~HandleNode, s:" | & s; 152 134 { 153 printf( " lnth:%u s:%p,\"", lnth, (void *)s ); 135 serr | nlOff; 136 serr | " lnth:" | lnth | " s:" | (void *)s | ",\""; 154 137 for ( i; lnth ) { 155 printf( "%c", s[i] );138 serr | s[i]; 156 139 } // for 157 printf( "\" flink:%p blink:%p\n", flink, blink ); 140 serr | "\" flink:" | flink | " blink:" | blink | nl; 141 serr | nlOn; 158 142 } 159 143 #endif // VbyteDebug … … 192 176 193 177 VbyteHeap * DEBUG_string_heap() { 194 //assert( ambient_string_sharectx->activeHeap && "No sharing context is active" );178 assert( ambient_string_sharectx->activeHeap && "No sharing context is active" ); 195 179 return ambient_string_sharectx->activeHeap; 196 180 } … … 346 330 s.shareSet_prev = &s; 347 331 s.shareSet_next = &s; 348 }332 } 349 333 350 334 static void eagerCopyCtorHelper(string_res & s, const char * rhs, size_t rhslnth) with(s) { … … 356 340 (shareSet_owns_ulink){ true }; 357 341 } 358 Handle.s = VbyteAlloc( *Handle.ulink, rhslnth);342 Handle.s = VbyteAlloc(*Handle.ulink, rhslnth); 359 343 Handle.lnth = rhslnth; 360 344 memmove( Handle.s, rhs, rhslnth ); … … 408 392 void ?{}( string_res & s, VbyteHeap & heap, const char * rhs, size_t rhslnth ) with(s) { 409 393 (Handle){ heap }; 410 Handle.s = VbyteAlloc( *Handle.ulink, rhslnth);394 Handle.s = VbyteAlloc(*Handle.ulink, rhslnth); 411 395 Handle.lnth = rhslnth; 412 396 (s.shareSet_owns_ulink){ false }; … … 414 398 s.shareSet_prev = &s; 415 399 s.shareSet_next = &s; 416 #ifdef VbyteDebug417 printHandleList( s.Handle );418 printf( "exit:constructor, s:%p\n", &s );419 #endif // VbyteDebug420 400 } 421 401 … … 555 535 556 536 static string_res & assign_(string_res & s, const char * buffer, size_t bsize, const string_res & valSrc) { 557 #ifdef VbyteDebug558 printf( "enter:assign_\n" );559 printHandleList( s.Handle );560 #endif // VbyteDebug561 562 537 string_res * shareSetStartPeer; 563 538 string_res * shareSetEndPeer; … … 639 614 } 640 615 641 #ifdef VbyteDebug642 printHandleList( s.Handle );643 printf( "exit:assign_\n" );644 #endif // VbyteDebug645 646 616 return s; 647 617 } … … 738 708 739 709 void append(string_res & str1, const char * buffer, size_t bsize) { 740 #ifdef VbyteDebug741 printf( "enter append %p %p %zd\n", &str1, buffer, bsize );742 printHandleList( str1.Handle );743 #endif // VbyteDebug744 710 size_t clnth = str1.Handle.lnth + bsize; 745 711 if ( str1.Handle.s + str1.Handle.lnth == buffer ) { // already juxtapose ? 746 712 // no-op 747 713 } else { // must copy some text 748 // if ( str1.Handle.s + str1.Handle.lnth == VbyteAlloc(*str1.Handle.ulink, 0) ) { // str1 at end of string area ? 749 if ( str1.Handle.s + str1.Handle.lnth == str1.Handle.ulink->EndVbyte ) { // str1 at end of string area ? 714 if ( str1.Handle.s + str1.Handle.lnth == VbyteAlloc(*str1.Handle.ulink, 0) ) { // str1 at end of string area ? 750 715 VbyteAlloc( *str1.Handle.ulink, bsize ); // create room for 2nd part at the end of string area 751 716 } else { // copy the two parts … … 758 723 } // if 759 724 str1.Handle.lnth = clnth; 760 #ifdef VbyteDebug761 printHandleList( str1.Handle );762 printf( "exit append\n" );763 #endif // VbyteDebug764 725 } 765 726 … … 977 938 static void AddThisAfter( HandleNode & s, HandleNode & n ) with(s) { 978 939 #ifdef VbyteDebug 979 printf( "enter:AddThisAfter, s:%p n:%p\n", &s, &n );940 serr | "enter:AddThisAfter, s:" | &s | " n:" | &n; 980 941 #endif // VbyteDebug 981 942 // Performance note: we are on the critical path here. MB has ensured that the verifies don't contribute to runtime (are compiled away, like they're supposed to be). … … 987 948 n.flink = &s; 988 949 #ifdef VbyteDebug 989 printHandleList( s ); 990 printf( "exit:AddThisAfter\n" ); 950 { 951 serr | "HandleList:"; 952 serr | nlOff; 953 for ( HandleNode *ni = HeaderPtr->flink; ni != HeaderPtr; ni = ni->flink ) { 954 serr | "\tnode:" | ni | " lnth:" | ni->lnth | " s:" | (void *)ni->s | ",\""; 955 for ( i; ni->lnth ) { 956 serr | ni->s[i]; 957 } // for 958 serr | "\" flink:" | ni->flink | " blink:" | ni->blink | nl; 959 } // for 960 serr | nlOn; 961 } 962 serr | "exit:AddThisAfter"; 991 963 #endif // VbyteDebug 992 964 } // AddThisAfter … … 997 969 static void DeleteNode( HandleNode & s ) with(s) { 998 970 #ifdef VbyteDebug 999 printf( "enter:DeleteNode, s:%p\n", &s ); 1000 printHandleList( s ); 971 serr | "enter:DeleteNode, s:" | &s; 1001 972 #endif // VbyteDebug 1002 973 flink->blink = blink; 1003 974 blink->flink = flink; 1004 975 #ifdef VbyteDebug 1005 printHandleList( s ); 1006 printf( "exit:DeleteNode\n" ); 976 serr | "exit:DeleteNode"; 1007 977 #endif // VbyteDebug 1008 978 } // DeleteNode … … 1014 984 static char * VbyteAlloc( VbyteHeap & s, int size ) with(s) { 1015 985 #ifdef VbyteDebug 1016 printf( "enter:VbyteAlloc, size:%d\n", size );986 serr | "enter:VbyteAlloc, size:" | size; 1017 987 #endif // VbyteDebug 1018 988 uintptr_t NoBytes; … … 1027 997 EndVbyte += size; 1028 998 #ifdef VbyteDebug 1029 printf( "exit:VbyteAlloc, r:%p EndVbyte:%p ExtVbyte:%p\n", (void *)r, (void *)EndVbyte, ExtVbyte );999 serr | "exit:VbyteAlloc, r:" | (void *)r | " EndVbyte:" | (void *)EndVbyte | " ExtVbyte:" | ExtVbyte; 1030 1000 #endif // VbyteDebug 1031 1001 return r; … … 1059 1029 1060 1030 1061 // Move HandleNode node s somewhere after the HandleNode node h so that it is in ascending order by the address in the1062 // byte string area.1063 1064 static void MoveThisAfter( HandleNode & s, HandleNode& h ) with(s) {1065 #ifdef VbyteDebug 1066 printf( "enter:MoveThisAfter, s:%p h:%p\n", &s, &h );1031 // Move an existing HandleNode node h somewhere after the current HandleNode node so that it is in ascending order by 1032 // the address in the byte string area. 1033 1034 static void MoveThisAfter( HandleNode & s, const HandleNode & h ) with(s) { 1035 #ifdef VbyteDebug 1036 serr | "enter:MoveThisAfter, s:" | & s | " h:" | & h; 1067 1037 #endif // VbyteDebug 1068 1038 verify( h.ulink != 0p ); 1069 1039 verify( s.ulink == h.ulink ); 1070 verify( s < h.s && "VbyteSM: Error - Cannot move byte strings as requested and keep handles in ascending order" ); 1040 if ( s < h.s ) { // check argument values 1041 // serr | "VbyteSM: Error - Cannot move byte string starting at:" | s | " after byte string starting at:" 1042 // | ( h->s ) | " and keep handles in ascending order"; 1043 // exit(-1 ); 1044 verify( 0 && "VbyteSM: Error - Cannot move byte strings as requested and keep handles in ascending order"); 1045 } // if 1071 1046 1072 1047 HandleNode *i; 1073 for ( i = h.flink; i != &s.ulink->Header && s > i->s; i = i->flink ); // find the position for this node after h1074 if ( & s != i->blink ) { // s just after h ? => nothing to move1048 for ( i = h.flink; i->s != 0 && s > ( i->s ); i = i->flink ); // find the position for this node after h 1049 if ( & s != i->blink ) { 1075 1050 DeleteNode( s ); 1076 1051 AddThisAfter( s, *i->blink ); 1077 1052 } // if 1078 1053 #ifdef VbyteDebug 1079 printHandleList( s ); 1080 printf( "exit:MoveThisAfter\n" ); 1054 { 1055 serr | "HandleList:"; 1056 serr | nlOff; 1057 for ( HandleNode *n = HeaderPtr->flink; n != HeaderPtr; n = n->flink ) { 1058 serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\""; 1059 for ( i; n->lnth ) { 1060 serr | n->s[i]; 1061 } // for 1062 serr | "\" flink:" | n->flink | " blink:" | n->blink | nl; 1063 } // for 1064 serr | nlOn; 1065 } 1066 serr | "exit:MoveThisAfter"; 1081 1067 #endif // VbyteDebug 1082 1068 } // MoveThisAfter … … 1093 1079 int ByteCmp( char *Src1, int Src1Start, int Src1Lnth, char *Src2, int Src2Start, int Src2Lnth ) { 1094 1080 #ifdef VbyteDebug 1095 printf( "enter:ByteCmp, Src1Start:%d Src1Lnth:%d Src2Start:%d Src2Lnth:%d", Src1Start, Src1Lnth, Src2Start, Src2Lnth );1081 serr | "enter:ByteCmp, Src1Start:" | Src1Start | " Src1Lnth:" | Src1Lnth | " Src2Start:" | Src2Start | " Src2Lnth:" | Src2Lnth; 1096 1082 #endif // VbyteDebug 1097 1083 int cmp; … … 1129 1115 } // for 1130 1116 #ifdef VbyteDebug 1131 printf( "exit:ByteCmp, cmp:%d\n", cmp );1117 serr | "exit:ByteCmp, cmp:" | cmp; 1132 1118 #endif // VbyteDebug 1133 1119 return cmp; … … 1140 1126 // the containing string has been moved. Hence, they only require that their string pointers be adjusted. 1141 1127 1142 void compaction( VbyteHeap & s ) with(s) { 1143 #ifdef VbyteDebug 1144 printf( "enter compaction\n" ); 1145 printHandleList( Header ); 1146 #endif // VbyteDebug 1147 char * obase, * nbase, * limit; 1128 void compaction(VbyteHeap & s) with(s) { 1129 HandleNode *h; 1130 char *obase, *nbase, *limit; 1148 1131 1149 1132 NoOfCompactions += 1; 1150 1133 EndVbyte = StartVbyte; 1151 for ( HandleNode * h = Header.flink; h != &Header; ) { 1134 h = Header.flink; // ignore header node 1135 for () { 1152 1136 memmove( EndVbyte, h->s, h->lnth ); 1153 1137 obase = h->s; … … 1157 1141 limit = obase + h->lnth; 1158 1142 h = h->flink; 1143 1159 1144 // check if any substrings are allocated within a string 1160 for ( ; h != &Header; h = h->flink ) { 1161 if ( h->s >= limit ) break; // outside of current string ? 1145 1146 for () { 1147 if ( h == &Header ) break; // end of header list ? 1148 if ( h->s >= limit ) break; // outside of current string ? 1162 1149 h->s = nbase + (( uintptr_t )h->s - ( uintptr_t )obase ); 1150 h = h->flink; 1163 1151 } // for 1152 if ( h == &Header ) break; // end of header list ? 1164 1153 } // for 1165 #ifdef VbyteDebug1166 printHandleList( Header );1167 printf( "exit compaction\n" );1168 #endif // VbyteDebug1169 1154 } // compaction 1170 1155 … … 1181 1166 // the heap. The heap is then compacted in the existing heap or into the newly allocated heap. 1182 1167 1183 void garbage( VbyteHeap & s, int minreq ) with(s) { 1184 #ifdef VbyteDebug 1185 printf( "enter:garbage\n" ); 1186 printHandleList( Header ); 1168 void garbage(VbyteHeap & s, int minreq ) with(s) { 1169 #ifdef VbyteDebug 1170 serr | "enter:garbage"; 1171 { 1172 serr | "HandleList:"; 1173 for ( HandleNode *n = Header.flink; n != &Header; n = n->flink ) { 1174 serr | nlOff; 1175 serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\""; 1176 for ( i; n->lnth ) { 1177 serr | n->s[i]; 1178 } // for 1179 serr | nlOn; 1180 serr | "\" flink:" | n->flink | " blink:" | n->blink; 1181 } // for 1182 } 1187 1183 #endif // VbyteDebug 1188 1184 int AmountUsed, AmountFree; … … 1208 1204 }// if 1209 1205 #ifdef VbyteDebug 1210 printHandleList( Header ); 1211 printf( "exit:garbage\n" ); 1206 { 1207 serr | "HandleList:"; 1208 for ( HandleNode *n = Header.flink; n != &Header; n = n->flink ) { 1209 serr | nlOff; 1210 serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\""; 1211 for ( i; n->lnth ) { 1212 serr | n->s[i]; 1213 } // for 1214 serr | nlOn; 1215 serr | "\" flink:" | n->flink | " blink:" | n->blink; 1216 } // for 1217 } 1218 serr | "exit:garbage"; 1212 1219 #endif // VbyteDebug 1213 1220 } // garbage 1221 1222 #undef VbyteDebug 1223 1214 1224 1215 1225 … … 1219 1229 void extend( VbyteHeap & s, int size ) with (s) { 1220 1230 #ifdef VbyteDebug 1221 printf( "enter:extend, size:%d", size );1231 serr | "enter:extend, size:" | size; 1222 1232 #endif // VbyteDebug 1223 1233 char *OldStartVbyte; … … 1232 1242 free( OldStartVbyte ); // release old heap 1233 1243 #ifdef VbyteDebug 1234 printf( "exit:extend, CurrSize: %d\n", CurrSize );1244 serr | "exit:extend, CurrSize:" | CurrSize; 1235 1245 #endif // VbyteDebug 1236 1246 } // extend … … 1238 1248 //WIP 1239 1249 #if 0 1250 1240 1251 // Extend the size of the byte-string area by creating a new area and copying the old area into it. The old byte-string 1241 1252 // area is deleted. … … 1243 1254 void VbyteHeap::reduce( int size ) { 1244 1255 #ifdef VbyteDebug 1245 printf( "enter:reduce, size: %d", size );1256 serr | "enter:reduce, size:" | size; 1246 1257 #endif // VbyteDebug 1247 1258 char *OldStartVbyte; … … 1256 1267 delete OldStartVbyte; // release old heap 1257 1268 #ifdef VbyteDebug 1258 printf( "exit:reduce, CurrSize: %d", CurrSize );1269 !serr | "exit:reduce, CurrSize:" | CurrSize; 1259 1270 #endif // VbyteDebug 1260 1271 } // reduce 1261 #endif // 0 1272 1273 1274 #endif -
libcfa/src/collections/string_res.hfa
r893fb47 ra9049dd 10 10 // Created On : Fri Sep 03 11:00:00 2021 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 11 18:56:08202613 // Update Count : 8 412 // Last Modified On : Thu May 7 13:14:04 2026 13 // Update Count : 83 14 14 // 15 15 … … 31 31 32 32 char * s; // pointer to byte string 33 size_t lnth;// length of byte string33 unsigned int lnth; // length of byte string 34 34 }; // HandleNode 35 35
Note:
See TracChangeset
for help on using the changeset viewer.