Changeset 218096f for libcfa


Ignore:
Timestamp:
Sep 28, 2021, 2:45:42 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
0f781fb8
Parents:
056cbdb
Message:

String performance improvements

Location:
libcfa/src/containers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/string_res.cfa

    r056cbdb r218096f  
    1717#include <stdlib.hfa>  // e.g. malloc
    1818#include <string.h>    // e.g. strlen
     19#include <assert.h>
    1920
    2021//######################### VbyteHeap "header" #########################
     
    102103// creator.
    103104
    104 void ?{}( HandleNode & this ) with(this) {
     105static inline void ?{}( HandleNode & this ) with(this) {
    105106#ifdef VbyteDebug
    106107    serr | "enter:HandleNode::HandleNode, this:" | &this;
     
    117118// collection.
    118119
    119 void ?{}( HandleNode & this, VbyteHeap & vh ) with(this) {
     120static inline void ?{}( HandleNode & this, VbyteHeap & vh ) with(this) {
    120121#ifdef VbyteDebug
    121122    serr | "enter:HandleNode::HandleNode, this:" | &this;
     
    133134// is the responsibility of the creator to destroy it.
    134135
    135 void ^?{}( HandleNode & this ) with(this) {
     136static inline void ^?{}( HandleNode & this ) with(this) {
    136137#ifdef VbyteDebug
    137138    serr | "enter:HandleNode::~HandleNode, this:" | & this;
     
    223224void ?{}(string_res &s, const string_res & s2, StrResInitMode mode, size_t start, size_t end ) {
    224225
    225     (s.Handle){ HeapArea };
     226    verify( start <= end && end <= s2.Handle.lnth );
     227
     228    (s.Handle){};
    226229    s.Handle.s = s2.Handle.s + start;
    227230    s.Handle.lnth = end - start;
    228     MoveThisAfter(s.Handle, s2.Handle );                        // insert this handle after rhs handle
     231    AddThisAfter(s.Handle, s2.Handle );                 // insert this handle after rhs handle
    229232    // ^ bug?  skip others at early point in string
    230233   
     
    234237        s.shareEditSet_next = &s;
    235238    } else {
    236         assert( mode == SHARE_EDITS );
     239        verify( mode == SHARE_EDITS );
    237240
    238241        // s2 is logically const but not implementation const
     
    297300    char *limit = pasting.Handle.s + pasting.Handle.lnth;
    298301    for (string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next) {
    299         assert (p->Handle.s >= beforeBegin);
     302        verify (p->Handle.s >= beforeBegin);
    300303        if ( p->Handle.s >= afterBegin ) {
    301             assert ( p->Handle.s <= afterBegin + afterLen );
    302             assert ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
     304            verify ( p->Handle.s <= afterBegin + afterLen );
     305            verify ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
    303306            // p starts after the edit
    304307            // take start and end as end-anchored
     
    318321            } else {
    319322                // p ends after the edit
    320                 assert ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
     323                verify ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
    321324                // take end as end-anchored
    322325                // stretch-shrink p according to the edit
     
    328331            p->Handle.s = pasting.Handle.s + startOffsetFromStart;
    329332        } else {
    330             assert ( p->Handle.s < afterBegin );
     333            verify ( p->Handle.s < afterBegin );
    331334            // p starts during the edit
    332             assert( p->Handle.s + p->Handle.lnth >= beforeBegin + beforeLen );
     335            verify( p->Handle.s + p->Handle.lnth >= beforeBegin + beforeLen );
    333336            if ( p->Handle.s + p->Handle.lnth < afterBegin ) {
    334337                // p ends during the edit; p does not include the last character replaced
     
    374377    s.shareEditSet_prev->shareEditSet_next = s.shareEditSet_next;
    375378    s.shareEditSet_next->shareEditSet_prev = s.shareEditSet_prev;
    376     s.shareEditSet_next = &s;
    377     s.shareEditSet_prev = &s;
     379    // s.shareEditSet_next = &s;
     380    // s.shareEditSet_prev = &s;
    378381}
    379382
     
    385388    //TODO: Check if index is valid (no exceptions yet)
    386389    return Handle.s[index];
     390}
     391
     392void assignAt(const string_res &s, size_t index, char val) {
     393    string_res editZone = { s, SHARE_EDITS, index, index+1 };
     394    assign(editZone, &val, 1);
    387395}
    388396
     
    653661                NoBytes = ( uintptr_t )EndVbyte + size;         // try again
    654662                if ( NoBytes > ( uintptr_t )ExtVbyte ) {        // enough room for new byte-string ?
     663// unimplemented feature - assert, not verify
    655664assert( 0 && "need to implement actual growth" );
    656665                        // extend( size );                              // extend the byte-string area
     
    677686                //      | ( h->s ) | " and keep handles in ascending order";
    678687                // exit(-1 );
    679                 assert( 0 && "VbyteSM: Error - Cannot move byte strings as requested and keep handles in ascending order");
     688                verify( 0 && "VbyteSM: Error - Cannot move byte strings as requested and keep handles in ascending order");
    680689    } // if
    681690
     
    839848    if ( AmountFree < ( int )( CurrSize * 0.1 )) {      // free space less than 10% ?
    840849
     850// unimplemented feature - assert, not verify
    841851assert( 0 && "need to implement actual growth" );
    842852//              extend( CurrSize );                             // extend the heap
  • libcfa/src/containers/string_res.hfa

    r056cbdb r218096f  
    3131    unsigned int lnth;                                  // length of byte string
    3232}; // HandleNode
    33 
    34 void ?{}( HandleNode & );                       // constructor for header node
    35 
    36 void ?{}( HandleNode &, VbyteHeap & );          // constructor for nodes in the handle list
    37 void ^?{}( HandleNode & );                      // destructor for handle nodes
    3833
    3934extern VbyteHeap * DEBUG_string_heap;
     
    105100
    106101// Character access
     102void assignAt(const string_res &s, size_t index, char val);
    107103char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
    108104//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
Note: See TracChangeset for help on using the changeset viewer.