Ignore:
Timestamp:
Apr 25, 2025, 7:08:53 PM (8 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
7d02d35, ecfa58be
Parents:
65bd3c2
Message:

Rewrote the iostream traits to have a single assertion each, a table containing function pointers. This is just an experiment right now. It seems that it does cause significant speed up of assertion resolution, but for some reason also seems to add a flat overhead that mostly eats up that saving.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r65bd3c2 rae0c1c3  
    202202} // nl
    203203
     204static basic_ostream_data(ofstream) ofstream_basic_data = {
     205        sepPrt$,
     206        sepReset$,
     207        sepReset$,
     208        sepGetCur$,
     209        sepSetCur$,
     210        getNL$,
     211        setNL$,
     212        getANL$,
     213        setANL$,
     214        getPrt$,
     215        setPrt$,
     216        nlOn,
     217        nlOff,
     218        sep,
     219        nosep,
     220        sepOn,
     221        sepOff,
     222        sepGet,
     223        sepSet,
     224        sepGetTuple,
     225        sepSetTuple,
     226        ends,
     227        fmt,
     228};
     229
     230basic_ostream_data(ofstream) const & basic_ostream_table = ofstream_basic_data;
     231
     232static ostream_data(ofstream) ofstream_data;
     233
     234// This should be an initializer like for the basic table.
     235// But, initialization of a structure with an inline structure doesn't work.
     236__attribute__((constructor(200)))
     237static void __ofstream_data_init__() {
     238        basic_ostream_data(ofstream) & basic = ofstream_data;
     239        basic.sepPrt$ = sepPrt$;
     240        basic.sepReset$ = (void(*)(ofstream&))sepReset$;
     241        basic.sepReset$ = (void(*)(ofstream&, bool))sepReset$;
     242        basic.sepGetCur$ = sepGetCur$;
     243        basic.sepSetCur$ = sepSetCur$;
     244        basic.getNL$ = getNL$;
     245        basic.setNL$ = setNL$;
     246        basic.getANL$ = getANL$;
     247        basic.setANL$ = setANL$;
     248        basic.getPrt$ = getPrt$;
     249        basic.setPrt$ = setPrt$;
     250        basic.nlOn = nlOn;
     251        basic.nlOff = nlOff;
     252        basic.sep = sep;
     253        basic.nosep = nosep;
     254        basic.sepOn = sepOn;
     255        basic.sepOff = sepOff;
     256        basic.sepGet = sepGet;
     257        basic.sepSet = sepSet;
     258        basic.sepGetTuple = sepGetTuple;
     259        basic.sepSetTuple = sepSetTuple;
     260        basic.ends = ends;
     261        basic.fmt = fmt;
     262        ofstream_data.fail = fail;
     263        ofstream_data.clearerr = clearerr;
     264        ofstream_data.flush = flush;
     265        ofstream_data.open = open;
     266        ofstream_data.close = close;
     267        ofstream_data.write = write;
     268}
     269
     270ostream_data(ofstream) const & ostream_table = ofstream_data;
    204271
    205272// *********************************** ifstream ***********************************
     
    211278        nlOnOff$ = false;                                                                       // => skip newlines when reading single characters
    212279} // ?{}
     280
     281static basic_istream_data(ifstream) ifstream_basic_data = {
     282        getANL$,
     283        setANL$,
     284        nlOn,
     285        nlOff,
     286        fmt,
     287        ungetc,
     288        eof,
     289        clearerr,
     290};
     291
     292basic_istream_data(ifstream) const & basic_istream_table = ifstream_basic_data;
     293
     294static istream_data(ifstream) ifstream_data;
     295
     296// This should be an initializer like for the basic table.
     297// But, initialization of a structure with an inline structure doesn't work.
     298__attribute__((constructor(200)))
     299static void __ifstream_data_init__() {
     300        basic_istream_data(ifstream) & basic = ifstream_data;
     301        basic.getANL$ = getANL$;
     302        basic.setANL$ = setANL$;
     303        basic.nlOn = nlOn;
     304        basic.nlOff = nlOff;
     305        basic.fmt = fmt;
     306        basic.ungetc = ungetc;
     307        basic.eof = eof;
     308        basic.clearerr = clearerr;
     309        ifstream_data.fail = fail;
     310        ifstream_data.open = (void(*)(ifstream &, const char *, const char *))open;
     311        ifstream_data.open = (void(*)(ifstream &, const char *))open;
     312        ifstream_data.close = close;
     313        ifstream_data.read = read;
     314}
     315
     316istream_data(ifstream) const & istream_table = ifstream_data;
    213317
    214318bool getANL$( ifstream & os ) { return os.nlOnOff$; }
Note: See TracChangeset for help on using the changeset viewer.