Ignore:
Timestamp:
Apr 25, 2025, 7:08:53 PM (9 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/iostream.hfa

    r65bd3c2 rae0c1c3  
    2222
    2323forall( ostype & )
     24struct basic_ostream_data {
     25        // private
     26        bool (*sepPrt$)( ostype & );                                                    // get separator state (on/off)
     27        void (*sepReset$)( ostype & );                                                  // set separator state to default state
     28        void (*sepReset$)( ostype &, bool );                                    // set separator and default state
     29        const char * (*sepGetCur$)( ostype & );                         // get current separator string
     30        void (*sepSetCur$)( ostype &, const char [] );                  // set current separator string
     31        bool (*getNL$)( ostype & );                                                     // get newline
     32        bool (*setNL$)( ostype &, bool );                                               // set newline
     33        bool (*getANL$)( ostype & );                                                    // get auto newline (on/off)
     34        bool (*setANL$)( ostype &, bool );                                              // set auto newline (on/off), and return previous state
     35        bool (*getPrt$)( ostype & );                                                    // get fmt called in output cascade
     36        bool (*setPrt$)( ostype &, bool );                                              // set fmt called in output cascade
     37        // public
     38        void (*nlOn)( ostype & );                                                               // turn auto-newline state on
     39        void (*nlOff)( ostype & );                                                              // turn auto-newline state off
     40
     41        void (*sep)( ostype & );                                                                // turn separator state on
     42        void (*nosep)( ostype & );                                                              // turn separator state off
     43        bool (*sepOn)( ostype & );                                                              // set default state to on, and return previous state
     44        bool (*sepOff)( ostype & );                                                     // set default state to off, and return previous state
     45        const char * (*sepGet)( ostype & );                                     // get separator string
     46        void (*sepSet)( ostype &, const char [] );                              // set separator to string (15 character maximum)
     47        const char * (*sepGetTuple)( ostype & );                                // get tuple separator string
     48        void (*sepSetTuple)( ostype &, const char [] );         // set tuple separator to string (15 character maximum)
     49
     50        void (*ends)( ostype & );                                                               // end of output statement
     51        int (*fmt)( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     52}; // basic_ostream
     53
     54forall( ostype & )
     55struct ostream_data {
     56        inline basic_ostream_data( ostype );
     57        bool (*fail)( ostype & );                                                               // operation failed?
     58        void (*clearerr)( ostype & );
     59        int (*flush)( ostype & );
     60        void (*open)( ostype &, const char name[], const char mode[] );
     61        void (*close)( ostype & );
     62        ostype & (*write)( ostype &, const char [], size_t );
     63}; // ostream
     64
     65forall( ostype & )
    2466trait basic_ostream {
    25         // private
    26         bool sepPrt$( ostype & );                                                       // get separator state (on/off)
    27         void sepReset$( ostype & );                                                     // set separator state to default state
    28         void sepReset$( ostype &, bool );                                       // set separator and default state
    29         const char * sepGetCur$( ostype & );                            // get current separator string
    30         void sepSetCur$( ostype &, const char [] );                     // set current separator string
    31         bool getNL$( ostype & );                                                        // get newline
    32         bool setNL$( ostype &, bool );                                          // set newline
    33         bool getANL$( ostype & );                                                       // get auto newline (on/off)
    34         bool setANL$( ostype &, bool );                                         // set auto newline (on/off), and return previous state
    35         bool getPrt$( ostype & );                                                       // get fmt called in output cascade
    36         bool setPrt$( ostype &, bool );                                         // set fmt called in output cascade
    37         // public
    38         void nlOn( ostype & );                                                          // turn auto-newline state on
    39         void nlOff( ostype & );                                                         // turn auto-newline state off
    40 
    41         void sep( ostype & );                                                           // turn separator state on
    42         void nosep( ostype & );                                                         // turn separator state off
    43         bool sepOn( ostype & );                                                         // set default state to on, and return previous state
    44         bool sepOff( ostype & );                                                        // set default state to off, and return previous state
    45         const char * sepGet( ostype & );                                        // get separator string
    46         void sepSet( ostype &, const char [] );                         // set separator to string (15 character maximum)
    47         const char * sepGetTuple( ostype & );                           // get tuple separator string
    48         void sepSetTuple( ostype &, const char [] );            // set tuple separator to string (15 character maximum)
    49 
    50         void ends( ostype & );                                                          // end of output statement
    51         int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    52 }; // basic_ostream
     67        basic_ostream_data(ostype) const & basic_ostream_table;
     68};
    5369
    5470forall( ostype & | basic_ostream( ostype ) )
    5571trait ostream {
    56         bool fail( ostype & );                                                          // operation failed?
    57         void clearerr( ostype & );
    58         int flush( ostype & );
    59         void open( ostype &, const char name[], const char mode[] );
    60         void close( ostype & );
    61         ostype & write( ostype &, const char [], size_t );
    62 }; // ostream
     72        ostream_data(ostype) const & ostream_table;
     73};
    6374
    6475// forall( T )
     
    7788#define OSTYPE_VOID_IMPL( os, T ) \
    7889        void ?|?( ostype & os, T t ) { \
    79                 (ostype &)(os | t); ends( os ); \
     90                (ostype &)(os | t); \
     91                basic_ostream_table.ends( os ); \
    8092        } // ?|?
    8193
     
    308320
    309321forall( istype & )
     322struct basic_istream_data {
     323        // private
     324        bool (*getANL$)( istype & );                                                    // get scan newline (on/off)
     325        bool (*setANL$)( istype &, bool );                                              // set scan newline (on/off)
     326        // public
     327        void (*nlOn)( istype & );                                                               // read newline
     328        void (*nlOff)( istype & );                                                              // scan newline
     329        int (*fmt)( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     330        istype & (*ungetc)( char, istype & );
     331        bool (*eof)( istype & );
     332        void (*clearerr)( istype & );
     333}; // basic_istream
     334
     335forall( istype & )
     336struct istream_data {
     337        inline basic_istream_data( istype );
     338        bool (*fail)( istype & );
     339        void (*open)( istype & is, const char name[], const char mode[] );
     340        void (*open)( istype & is, const char name[] );
     341        void (*close)( istype & is );
     342        istype & (*read)( istype &, char [], size_t );
     343}; // istream
     344
     345forall( istype & )
    310346trait basic_istream {
    311         // private
    312         bool getANL$( istype & );                                                       // get scan newline (on/off)
    313         bool setANL$( istype &, bool );                                         // set scan newline (on/off)
    314         // public
    315         void nlOn( istype & );                                                          // read newline
    316         void nlOff( istype & );                                                         // scan newline
    317         int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    318         istype & ungetc( char, istype & );
    319         bool eof( istype & );
    320         void clearerr( istype & );
    321 }; // basic_istream
     347        basic_istream_data(istype) const & basic_istream_table;
     348};
    322349
    323350forall( istype & | basic_istream( istype ) )
    324351trait istream {
    325         bool fail( istype & );
    326         void open( istype & is, const char name[], const char mode[] );
    327         void open( istype & is, const char name[] );
    328         void close( istype & is );
    329         istype & read( istype &, char [], size_t );
    330 }; // istream
     352        istream_data(istype) const & istream_table;
     353};
    331354
    332355forall( T )
Note: See TracChangeset for help on using the changeset viewer.