Changeset 4e8df745
- Timestamp:
- Oct 26, 2021, 4:27:10 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 1733184
- Parents:
- 2b30370
- Location:
- libcfa/src/containers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/string_res.cfa
r2b30370 r4e8df745 18 18 19 19 #include <stdlib.hfa> // e.g. malloc 20 #include <string.h> // e.g. strlen21 20 #include <assert.h> 22 21 … … 43 42 44 43 45 static inlinevoid compaction( VbyteHeap & ); // compaction of the byte area46 static inlinevoid garbage( VbyteHeap &, int ); // garbage collect the byte area47 static inlinevoid extend( VbyteHeap &, int ); // extend the size of the byte area48 static inlinevoid reduce( VbyteHeap &, int ); // reduce the size of the byte area49 50 static inlinevoid ?{}( VbyteHeap &, size_t = 1000 );51 static inlinevoid ^?{}( VbyteHeap & );52 static inlinevoid ByteCopy( char *, int, int, char *, int, int ); // copy a block of bytes from one location in the heap to another53 static in line int ByteCmp( char *, int, int, char *, int, int ); // compare 2 blocks of bytes54 static inlinechar *VbyteAlloc( VbyteHeap &, int ); // allocate a block bytes in the heap55 static inlinechar *VbyteTryAdjustLast( VbyteHeap &, int );56 57 static inlinevoid AddThisAfter( HandleNode &, HandleNode & );58 static inlinevoid DeleteNode( HandleNode & );59 static inlinevoid MoveThisAfter( HandleNode &, const HandleNode & ); // move current handle after parameter handle44 static void compaction( VbyteHeap & ); // compaction of the byte area 45 static void garbage( VbyteHeap &, int ); // garbage collect the byte area 46 static void extend( VbyteHeap &, int ); // extend the size of the byte area 47 static void reduce( VbyteHeap &, int ); // reduce the size of the byte area 48 49 static void ?{}( VbyteHeap &, size_t = 1000 ); 50 static void ^?{}( VbyteHeap & ); 51 static void ByteCopy( char *, int, int, char *, int, int ); // copy a block of bytes from one location in the heap to another 52 static int ByteCmp( char *, int, int, char *, int, int ); // compare 2 blocks of bytes 53 static char *VbyteAlloc( VbyteHeap &, int ); // allocate a block bytes in the heap 54 static char *VbyteTryAdjustLast( VbyteHeap &, int ); 55 56 static void AddThisAfter( HandleNode &, HandleNode & ); 57 static void DeleteNode( HandleNode & ); 58 static void MoveThisAfter( HandleNode &, const HandleNode & ); // move current handle after parameter handle 60 59 61 60 62 61 // Allocate the storage for the variable sized area and intialize the heap variables. 63 62 64 static inlinevoid ?{}( VbyteHeap & this, size_t Size ) with(this) {63 static void ?{}( VbyteHeap & this, size_t Size ) with(this) { 65 64 #ifdef VbyteDebug 66 65 serr | "enter:VbyteHeap::VbyteHeap, this:" | &this | " Size:" | Size; … … 81 80 // Release the dynamically allocated storage for the byte area. 82 81 83 static inlinevoid ^?{}( VbyteHeap & this ) with(this) {82 static void ^?{}( VbyteHeap & this ) with(this) { 84 83 free( StartVbyte ); 85 84 } // ~VbyteHeap … … 92 91 // creator. 93 92 94 static inlinevoid ?{}( HandleNode & this ) with(this) {93 static void ?{}( HandleNode & this ) with(this) { 95 94 #ifdef VbyteDebug 96 95 serr | "enter:HandleNode::HandleNode, this:" | &this; … … 107 106 // collection. 108 107 109 static inlinevoid ?{}( HandleNode & this, VbyteHeap & vh ) with(this) {108 static void ?{}( HandleNode & this, VbyteHeap & vh ) with(this) { 110 109 #ifdef VbyteDebug 111 110 serr | "enter:HandleNode::HandleNode, this:" | &this; … … 124 123 // is the responsibility of the creator to destroy it. 125 124 126 static inlinevoid ^?{}( HandleNode & this ) with(this) {125 static void ^?{}( HandleNode & this ) with(this) { 127 126 #ifdef VbyteDebug 128 127 serr | "enter:HandleNode::~HandleNode, this:" | & this; … … 237 236 } 238 237 239 static inlinevoid eagerCopyCtorHelper(string_res &s, const char* rhs, size_t rhslnth) with(s) {238 static void eagerCopyCtorHelper(string_res &s, const char* rhs, size_t rhslnth) with(s) { 240 239 if( ambient_string_sharectx->activeHeap ) { 241 240 (Handle){ * ambient_string_sharectx->activeHeap }; … … 257 256 void ?{}(string_res &s, const char* rhs, size_t rhslnth) with(s) { 258 257 eagerCopyCtorHelper(s, rhs, rhslnth); 259 }260 261 // String literal constructor262 void ?{}(string_res &s, const char* rhs) {263 (s){ rhs, strlen(rhs) };264 258 } 265 259 … … 490 484 } 491 485 492 void ?=?(string_res &s, const char* other) {493 assign(s, other, strlen(other));494 }495 496 486 void ?=?(string_res &s, char other) { 497 487 assign(s, &other, 1); … … 543 533 544 534 void append(string_res &str1, const char * buffer, size_t bsize) { 545 size_t clnth = s ize(str1)+ bsize;546 if ( str1.Handle.s + s ize(str1)== buffer ) { // already juxtapose ?535 size_t clnth = str1.Handle.lnth + bsize; 536 if ( str1.Handle.s + str1.Handle.lnth == buffer ) { // already juxtapose ? 547 537 // no-op 548 538 } else { // must copy some text 549 if ( str1.Handle.s + s ize(str1)== VbyteAlloc(*str1.Handle.ulink, 0) ) { // str1 at end of string area ?539 if ( str1.Handle.s + str1.Handle.lnth == VbyteAlloc(*str1.Handle.ulink, 0) ) { // str1 at end of string area ? 550 540 VbyteAlloc( *str1.Handle.ulink, bsize ); // create room for 2nd part at the end of string area 551 541 } else { // copy the two parts … … 553 543 char * str1oldBuf = str1.Handle.s; // must read after VbyteAlloc call in case it gs's 554 544 str1.Handle.s = str1newBuf; 555 ByteCopy( str1.Handle.s, 0, str1.Handle.lnth, str1oldBuf, 0, str1.Handle.lnth);545 memcpy( str1.Handle.s, str1oldBuf, str1.Handle.lnth ); 556 546 } // if 557 ByteCopy( str1.Handle.s, str1.Handle.lnth, bsize, (char*)buffer, 0, (int)bsize); 558 // VbyteHeap & this, char *Dst, int DstStart, int DstLnth, char *Src, int SrcStart, int SrcLnth 547 memcpy( str1.Handle.s + str1.Handle.lnth, buffer, bsize ); 559 548 } // if 560 549 str1.Handle.lnth = clnth; … … 569 558 } 570 559 571 void ?+=?(string_res &s, const char* other) {572 append( s, other, strlen(other) );573 }574 560 575 561 … … 748 734 // Add a new HandleNode node n after the current HandleNode node. 749 735 750 static inlinevoid AddThisAfter( HandleNode & this, HandleNode & n ) with(this) {736 static void AddThisAfter( HandleNode & this, HandleNode & n ) with(this) { 751 737 #ifdef VbyteDebug 752 738 serr | "enter:AddThisAfter, this:" | &this | " n:" | &n; … … 778 764 // Delete the current HandleNode node. 779 765 780 static inlinevoid DeleteNode( HandleNode & this ) with(this) {766 static void DeleteNode( HandleNode & this ) with(this) { 781 767 #ifdef VbyteDebug 782 768 serr | "enter:DeleteNode, this:" | &this; … … 794 780 // allocation, the garbage collection routine is called. 795 781 796 static inline char *VbyteAlloc( VbyteHeap & this, int size ) with(this) {782 static char * __attribute__((noinline)) VbyteAlloc( VbyteHeap & this, int size ) with(this) { 797 783 #ifdef VbyteDebug 798 784 serr | "enter:VbyteAlloc, size:" | size; … … 804 790 if ( NoBytes > ( uintptr_t )ExtVbyte ) { // enough room for new byte-string ? 805 791 garbage( this, size ); // firer up the garbage collector 806 NoBytes = ( uintptr_t )EndVbyte + size; // try again 807 if ( NoBytes > ( uintptr_t )ExtVbyte ) { // enough room for new byte-string ? 808 assert( 0 && "garbage run did not free up required space" ); 809 } // if 792 verify( (( uintptr_t )EndVbyte + size) <= ( uintptr_t )ExtVbyte && "garbage run did not free up required space" ); 810 793 } // if 811 794 r = EndVbyte; … … 826 809 // VbyteAlloc to claim the new space, while doing optimal copying from old to new, then free old. 827 810 828 static inlinechar * VbyteTryAdjustLast( VbyteHeap & this, int delta ) with(this) {811 static char * VbyteTryAdjustLast( VbyteHeap & this, int delta ) with(this) { 829 812 830 813 if ( ( uintptr_t )EndVbyte + delta <= ( uintptr_t )ExtVbyte ) { … … 848 831 // the address in the byte string area. 849 832 850 static inlinevoid MoveThisAfter( HandleNode & this, const HandleNode & h ) with(this) {833 static void MoveThisAfter( HandleNode & this, const HandleNode & h ) with(this) { 851 834 #ifdef VbyteDebug 852 835 serr | "enter:MoveThisAfter, this:" | & this | " h:" | & h; -
libcfa/src/containers/string_res.hfa
r2b30370 r4e8df745 17 17 18 18 #include <fstream.hfa> 19 #include <string.h> // e.g. strlen 19 20 20 21 … … 72 73 // Constructors, Assignment Operators, Destructor 73 74 void ?{}(string_res &s); // empty string 74 void ?{}(string_res &s, const char* initial); // copy from string literal (NULL-terminated)75 75 void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer 76 static inline void ?{}(string_res &s, const char* rhs) { // copy from string literal (NULL-terminated) 77 (s){ rhs, strlen(rhs) }; 78 } 76 79 77 80 void ?{}(string_res &s, const string_res & s2) = void; … … 85 88 86 89 void assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer 87 void ?=?(string_res &s, const char* other); // copy from string literal (NULL-terminated) 90 static inline void ?=?(string_res &s, const char* other) { // copy from string literal (NULL-terminated) 91 assign(s, other, strlen(other)); 92 } 88 93 void ?=?(string_res &s, const string_res &other); 89 94 void ?=?(string_res &s, string_res &other); … … 97 102 98 103 // Concatenation 104 void append(string_res &s, const char* buffer, size_t bsize); 99 105 void ?+=?(string_res &s, char other); // append a character 100 106 void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string 101 void ?+=?(string_res &s, const char* other); 102 void append(string_res &s, const char* buffer, size_t bsize); 107 static inline void ?+=?(string_res &s, const char* other) { 108 append( s, other, strlen(other) ); 109 } 103 110 104 111 // Character access
Note: See TracChangeset
for help on using the changeset viewer.