Changeset 2b30370


Ignore:
Timestamp:
Oct 20, 2021, 4:38:37 PM (12 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
enum, master, pthread-emulation, qualifiedEnum
Children:
4e8df745
Parents:
0ca15b7
Message:

Bug fixes for empty-string from no-arg ctor with sharing off

Files:
3 edited

Legend:

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

    r0ca15b7 r2b30370  
    209209    // Store auto-newline state so it can be restored
    210210    bool anl = getANL$(out);
    211     nlOff(out);
    212     for (size_t i = 0; i < s.Handle.lnth; i++) {
    213         // Need to re-apply on the last output operator, for whole-statement version
    214         if (anl && i == s.Handle.lnth-1) nlOn(out);
    215         out | s[i];
    216     }
    217     return out;
     211    if( s.Handle.lnth == 0 ) {
     212        sout | "";
     213    } else {
     214        nlOff(out);
     215        for (size_t i = 0; i < s.Handle.lnth; i++) {
     216            // Need to re-apply on the last output operator, for whole-statement version
     217            if (anl && i == s.Handle.lnth-1) nlOn(out);
     218            out | s[i];
     219        }
     220    }
    218221}
    219222
     
    223226        (Handle){ * ambient_string_sharectx->activeHeap };
    224227        (shareEditSet_owns_ulink){ false };
     228        verify( Handle.s == 0p && Handle.lnth == 0 );
    225229    } else {
    226230        (Handle){ * new( (size_t) 10 ) };  // TODO: can I lazily avoid allocating for empty string
    227231        (shareEditSet_owns_ulink){ true };
     232        Handle.s = Handle.ulink->StartVbyte;
     233        verify( Handle.lnth == 0 );
    228234    }
    229235    s.shareEditSet_prev = &s;
  • tests/collections/.expect/string-api-coverage.txt

    r0ca15b7 r2b30370  
    11hello hello hello
     2
     3hello
    24true false
    35true false
  • tests/collections/string-api-coverage.cfa

    r0ca15b7 r2b30370  
    3737
    3838    // IO operator, x2
    39     sout | s | s | s;
     39    sout | s | s | s;  // hello hello hello
     40
     41    // empty ctor then assign
     42    string sxx;
     43    sout | sxx;  // (blank line)
     44    sxx = s;
     45    sout | sxx;  // hello
    4046
    4147    // Comparisons
Note: See TracChangeset for help on using the changeset viewer.