Ignore:
Timestamp:
Apr 11, 2025, 12:29:56 AM (9 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
d03a386
Parents:
3f631d6
Message:

Make string operator-overload costs match their intuitively equivalent arithmetics.

Replace many by-reference string args with by-value args to work around noise from the reference-cost column.

Use a special arithmetic type for the factor argument of ?*? to match conversion cost of (char*int=int).

Removes cost-function noise of char-arithmetic operators being preferred over their string-concatenation equivalents in the reference-cost column.

Notably, all former Spanish-A and numeric outputs have become ambiguous or been associated with a reproducible bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.cfa

    r3f631d6 r570e7ad  
    4040}
    4141
    42 void ?{}( string & s, const string & c ) {
     42void ?{}( string & s, string c ) {  // c is a memcpy of the real src string
    4343        (s.inner) { malloc() };
    4444        ?{}( *s.inner, *c.inner, COPY_VALUE );
    4545}
    4646
    47 void ?{}( string & s, const string & s2, size_t maxlen ) {
     47void ?{}( string & s, string s2, size_t maxlen ) {
    4848        (s.inner) { malloc() };
    4949        ?{}( *s.inner, *s2.inner, COPY_VALUE, maxlen );
    5050}
    5151
    52 
    53 void ?{}( string & s, string & c ) {
    54         ?{}( s, (const string &) c );
    55 }
    56 
    57 void ?{}( string & s, const char c ) {
     52void ?{}( string & s, char c ) {
    5853        (s.inner) { malloc() };
    5954        ?{}( *s.inner, c );
     
    7065}
    7166
    72 void ?{}( string & s, ssize_t rhs ) {
     67void ?{}( string & s, signed long int rhs ) {
    7368        (s.inner) { malloc() };
    7469        ?{}( *s.inner, rhs );
     
    151146// Assignment
    152147
    153 string & ?=?( string & s, const string & c ) {
    154         (*s.inner) = (*c.inner);
    155         return s;
    156 }
    157 
    158 string & ?=?( string & s, string & c ) {
     148string & ?=?( string & s, string c ) {
    159149        (*s.inner) = (*c.inner);
    160150        return s;
     
    181171}
    182172
    183 string & ?=?( string & s, ssize_t rhs ) {
     173string & ?=?( string & s, signed long int rhs ) {
    184174        (*s.inner) = rhs;
    185175        return s;
     
    324314}
    325315
    326 string ?+?( const string & s, char c ) {
     316string ?+?( string s, char c ) {
    327317        string ret = s;
    328318        ret += c;
     
    330320}
    331321
    332 string ?+?( char c, const string & s ) {
     322string ?+?( char c, string s ) {
    333323        string ret = c;
    334324        ret += s;
     
    336326}
    337327
    338 string ?+?( const string & s, const string & s2 ) {
     328string ?+?( string s, string s2 ) {
    339329        string ret = s;
    340330        ret += s2;
     
    360350}
    361351
    362 string ?+?( const char * s1, const string & s2 ) {
     352string ?+?( const char * s1, string s2 ) {
    363353        string ret = s1;
    364354        ret += s2;
     
    366356}
    367357
    368 string ?+?( const string & s, const char * c ) {
     358string ?+?( string s, const char * c ) {
    369359        string ret = s;
    370360        ret += c;
     
    381371// Repetition
    382372
    383 void ?*=?( string & s, size_t factor ) {
     373void ?*=?( string & s, strmul_factor_t factor ) {
    384374        (*s.inner) *= factor;
    385375}
    386376
    387 string ?*?( const string & s, size_t factor ) {
     377string ?*?( string s, strmul_factor_t factor ) {
    388378        string ret = s;
    389379        ret *= factor;
     
    391381}
    392382
    393 string ?*?( char c, size_t factor ) {
     383string ?*?( char c, strmul_factor_t factor ) {
    394384        string ret = c;
    395385        ret *= factor;
     
    397387}
    398388
    399 string ?*?( const char * s, size_t factor ) {
     389string ?*?( const char * s, strmul_factor_t factor ) {
    400390        string ret = s;
    401391        ret *= factor;
Note: See TracChangeset for help on using the changeset viewer.