Changeset 176


Ignore:
Timestamp:
Jul 8, 2008, 10:03:28 AM (11 years ago)
Author:
lindanl
Message:

Inlining reorganization; delete excess inline keywords; macros for critical code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine.c

    r175 r176  
    236236
    237237template <class B>
    238 inline void ParsingEngine<B>::AdvanceBuffers(){
     238void ParsingEngine<B>::AdvanceBuffers(){
    239239#if defined(PAPI) and defined(CODE_CLOCKING) and (CODE_CLOCKING == ADVANCE_BUFFERS)
    240240        code_clocker->cc_start_interval();
     
    271271
    272272template <>
    273 inline void ParsingEngine<U16_Buffer>::AdvanceBuffers(){
     273void ParsingEngine<U16_Buffer>::AdvanceBuffers(){
    274274#if defined(PAPI) and defined(CODE_CLOCKING) and (CODE_CLOCKING == ADVANCE_BUFFERS)
    275275        code_clocker->cc_start_interval();
     
    335335}
    336336
    337 template <class B>
    338 inline void ParsingEngine<B>::Advance(int n) {
    339         buffer_rel_pos += n;
    340   if (buffer_rel_pos >= BUFFER_SIZE) { 
    341         FinalizeBuffer_action();
    342         AdvanceBuffers();
    343   }
    344 }
     337//template <class B>
     338//inline void ParsingEngine<B>::Advance(int n) {
     339//      buffer_rel_pos += n;
     340//  if (buffer_rel_pos >= BUFFER_SIZE) {       
     341//      FinalizeBuffer_action();
     342//      AdvanceBuffers();
     343//  }
     344//}
     345
     346#define Advance(n) \
     347do {\
     348        buffer_rel_pos += n; \
     349        if (buffer_rel_pos >= BUFFER_SIZE) {    \
     350                FinalizeBuffer_action();\
     351        AdvanceBuffers();\
     352        }\
     353} while(0)
     354
    345355
    346356template <class B>
    347 inline void ParsingEngine<B>::AdjustBufferEndForIncompleteSequences() {
     357void ParsingEngine<B>::AdjustBufferEndForIncompleteSequences() {
    348358}
    349359
    350360template <>
    351 inline void ParsingEngine<UTF8_Buffer>::AdjustBufferEndForIncompleteSequences() {
     361void ParsingEngine<UTF8_Buffer>::AdjustBufferEndForIncompleteSequences() {
    352362        if (*(cur()-1) >= 0xC0) buffer_rel_pos--;
    353363        else if (*(cur()-2) >= 0xE0) buffer_rel_pos -= 2;
     
    356366
    357367template <>
    358 inline void ParsingEngine<U16_Buffer>::AdjustBufferEndForIncompleteSequences() {
     368void ParsingEngine<U16_Buffer>::AdjustBufferEndForIncompleteSequences() {
    359369        unsigned short last_u16_unit = *(GetCodeUnitPtr(AbsPos()-1));
    360370        if ((last_u16_unit >= 0xD800) & (last_u16_unit <= 0xDC00)) buffer_rel_pos--;
     
    363373
    364374#ifndef OPTIMIZE_SHORT_SCAN
    365 template <class B>
    366 inline void ParsingEngine<B>::ScanTo(int item) {
    367   buffer_rel_pos = bitstream_scan(buf->item_stream[item],
    368                                       buffer_rel_pos);
    369   while (buffer_rel_pos >= BUFFER_SIZE) {
    370         AdjustBufferEndForIncompleteSequences();
    371         FinalizeBuffer_action();
    372         AdvanceBuffers();
    373         buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
    374   }
    375 }
     375//template <class B>
     376//inline void ParsingEngine<B>::ScanTo(int item) {
     377//  buffer_rel_pos = bitstream_scan(buf->item_stream[item],
     378//                                      buffer_rel_pos);
     379//  while (buffer_rel_pos >= BUFFER_SIZE) {
     380//      AdjustBufferEndForIncompleteSequences();
     381//      FinalizeBuffer_action();
     382//      AdvanceBuffers();
     383//      buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     384//  }
     385//}
     386
     387#define ScanTo(item) \
     388do {\
     389  buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     390  while (buffer_rel_pos >= BUFFER_SIZE) {\
     391        AdjustBufferEndForIncompleteSequences();\
     392        FinalizeBuffer_action();\
     393        AdvanceBuffers();\
     394        buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     395  }\
     396} while(0)
     397
     398
     399
    376400#endif
    377401
     
    403427}
    404428
    405 #ifdef OPTIMIZE_SHORT_SCAN
    406 template <class B>
    407 inline void ParsingEngine<B>::ScanTo(int item) {
    408   SIMD_type * stream = buf->item_stream[item];
    409   unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + buffer_rel_pos/8);
    410   unsigned long bitstream_slice = *bitstream_ptr >> buffer_rel_pos % 8;
    411   if (bitstream_slice != 0) {
    412     buffer_rel_pos += __builtin_ctzl(bitstream_slice);
    413   }
    414   else {
    415     buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);
    416     buffer_rel_pos += bitstream_scan0((SIMD_type *) &bitstream_ptr[1]);
    417     while (buffer_rel_pos >= BUFFER_BLOCKS * BLOCKSIZE) {
    418         buffer_rel_pos = BUFFER_BLOCKS * BLOCKSIZE;
    419         AdjustBufferEndForIncompleteSequences();
    420         FinalizeBuffer_action();
    421         AdvanceBuffers();
    422       buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
    423     }
    424   }
    425 }
    426 #endif
    427 
    428 template <class B>
    429 inline void ParsingEngine<B>::WF_Error (XML_Constraint errCode) {
     429//#ifdef OPTIMIZE_SHORT_SCAN
     430//template <class B>
     431//inline void ParsingEngine<B>::ScanTo(int item) {
     432//  SIMD_type * stream = buf->item_stream[item];
     433//  unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) stream) + buffer_rel_pos/8);
     434//  unsigned long bitstream_slice = *bitstream_ptr >> buffer_rel_pos % 8;
     435//  if (bitstream_slice != 0) {
     436//    buffer_rel_pos += __builtin_ctzl(bitstream_slice);
     437//  }
     438//  else {
     439//    buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);
     440//    buffer_rel_pos += bitstream_scan0((SIMD_type *) &bitstream_ptr[1]);
     441//    while (buffer_rel_pos >= BUFFER_BLOCKS * BLOCKSIZE) {
     442//      buffer_rel_pos = BUFFER_BLOCKS * BLOCKSIZE;
     443//      AdjustBufferEndForIncompleteSequences();
     444//      FinalizeBuffer_action();
     445//      AdvanceBuffers();
     446//      buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     447//    }
     448//  }
     449//}
     450//#endif
     451
     452template <class B>
     453void ParsingEngine<B>::WF_Error (XML_Constraint errCode) {
    430454        printf("Error at position %i in input.\n", AbsPos());
    431455        ShowConstraintError(errCode);
     
    436460
    437461template <class B>
    438 inline void ParsingEngine<B>::Validity_Error (XML_Constraint errCode) {
     462void ParsingEngine<B>::Validity_Error (XML_Constraint errCode) {
    439463        printf("Error at position %i in input.\n", AbsPos());
    440464        ShowConstraintError(errCode);
     
    444468       
    445469template <class B>
    446 inline void ParsingEngine<B>::Syntax_Error (XML_NonTerminal errNT) {
     470void ParsingEngine<B>::Syntax_Error (XML_NonTerminal errNT) {
    447471        printf("Error at position %i in input.\n", AbsPos());
    448472        ShowSyntaxError(errNT);
     
    454478/* Parse a comment beginning "<!--" */
    455479template <class B>
    456 inline void ParsingEngine<B>::Parse_Comment() {
     480void ParsingEngine<B>::Parse_Comment() {
    457481
    458482        Advance(4); /* Skip "<!--". */
     
    495519/* Parse a CDATA section beginning "<![CDATA". */
    496520template <class B>
    497 inline void ParsingEngine<B>::Parse_CDATA() {
     521void ParsingEngine<B>::Parse_CDATA() {
    498522                Advance(8); /* Skip "<![CDATA". */
    499523        if (!AtChar<B::Base,'['>(cur())) {
     
    518542
    519543template <class B>
    520 inline void ParsingEngine<B>::Parse_EntityRef() {
     544void ParsingEngine<B>::Parse_EntityRef() {
    521545    Advance(1);  // skip "&"
    522546        int nameID = Parse_Name();  /* Name delimiter */
     
    566590
    567591template <class B>
    568 inline void ParsingEngine<B>::Parse_EntityRef_inMixed(symbol_set_t elems) {
     592void ParsingEngine<B>::Parse_EntityRef_inMixed(symbol_set_t elems) {
    569593    Advance(1);  // skip "&"
    570594        int nameID = Parse_Name();  /* Name delimiter */
     
    614638
    615639template <class B>
    616 inline void ParsingEngine<B>::Parse_EntityRef_inAnyContent() {
     640void ParsingEngine<B>::Parse_EntityRef_inAnyContent() {
    617641    Advance(1);  // skip "&"
    618642        int nameID = Parse_Name();  /* Name delimiter */
     
    662686
    663687template <class B>
    664 inline void ParsingEngine<B>::Parse_ValidEntityRef(CM_RegExp * cre, int & cur_state) {
     688void ParsingEngine<B>::Parse_ValidEntityRef(CM_RegExp * cre, int & cur_state) {
    665689    Advance(1);  // skip "&"
    666690        int nameID = Parse_Name();  /* Name delimiter */
     
    710734       
    711735template <class B>
    712 inline void ParsingEngine<B>::Parse_CharRef() {
     736void ParsingEngine<B>::Parse_CharRef() {
    713737        Advance(2);  // skip "&#"
    714738        int ch_val = 0;
     
    746770
    747771template <class B>
    748 inline void ParsingEngine<B>::Parse_PI (){
     772void ParsingEngine<B>::Parse_PI (){
    749773        int nameID;
    750774        Advance(2); /* Skip "<?". */
     
    10851109
    10861110template <class B>
    1087 inline void ParsingEngine<B>::Parse_WF_Element() {
     1111void ParsingEngine<B>::Parse_WF_Element() {
    10881112        bool is_emptyStartTag = false;
    10891113        int nameID = Parse_WF_StartTag(is_emptyStartTag);
     
    10991123
    11001124template <class B>
    1101 inline void ParsingEngine<B>::Parse_WF_Content() {
     1125void ParsingEngine<B>::Parse_WF_Content() {
    11021126        do {
    11031127                text_or_markup_start = AbsPos();
     
    11531177
    11541178template <class B>
    1155 inline void ParsingEngine<B>::ParseContent() {
     1179void ParsingEngine<B>::ParseContent() {
    11561180        DocumentStart_action();
    11571181        bool is_emptyStartTag = false;
     
    12131237
    12141238template <class B>
    1215 inline void ParsingEngine<B>::Parse_DocType (){
     1239void ParsingEngine<B>::Parse_DocType (){
    12161240
    12171241        int old_abspos, start_pos;
     
    12891313
    12901314template <class B>
    1291 inline void ParsingEngine<B>::Parse_ExternalID (char *& systemLiteral, char *& pubidLiteral){
     1315void ParsingEngine<B>::Parse_ExternalID (char *& systemLiteral, char *& pubidLiteral){
    12921316        int quot_start, lgth;
    12931317        if(at_SYSTEM<B::Base>(cur())){
     
    13241348
    13251349template <class B>
    1326 inline void ParsingEngine<B>::Parse_SystemLiteral (){
     1350void ParsingEngine<B>::Parse_SystemLiteral (){
    13271351        unsigned char quoteCh;
    13281352        if(AtQuote<B::Base>(cur())){
     
    13411365
    13421366template <class B>
    1343 inline void ParsingEngine<B>::Parse_PubidLiteral (){
     1367void ParsingEngine<B>::Parse_PubidLiteral (){
    13441368        unsigned char quoteCh;
    13451369        quoteCh = cur()[0];
     
    13551379
    13561380template <class B>
    1357 inline void ParsingEngine<B>::Parse_IntSubset (){
     1381void ParsingEngine<B>::Parse_IntSubset (){
    13581382       
    13591383        while(1){
     
    13971421
    13981422template <class B>
    1399 inline void ParsingEngine<B>::Parse_PEReference (){
     1423void ParsingEngine<B>::Parse_PEReference (){
    14001424
    14011425        Advance(1); /* Skip "%". */
     1426        fprintf(stderr,"Parameter Reference has not been completed yet.\n");
     1427        exit(-1);
    14021428        int nameID = Parse_Name();
    14031429        if (AtChar<B::Base,';'>(cur())) {
     
    14331459
    14341460template <class B>
    1435 inline void ParsingEngine<B>::Parse_Elementdecl (){
     1461void ParsingEngine<B>::Parse_Elementdecl (){
    14361462
    14371463        Advance(7); /* Skip "<!ELEMENT". */
     
    14931519}
    14941520template <class B>
    1495 inline ContentModel * ParsingEngine<B>::Parse_RemainingMixed (){
     1521ContentModel * ParsingEngine<B>::Parse_RemainingMixed (){
    14961522        CM_Mixed * r = new CM_Mixed();
    14971523        Advance(7);  /* Skip "#PCDATA". */
     
    15261552
    15271553template <class B>
    1528 inline Content_RE * ParsingEngine<B>::Parse_RemainingChildren (){
     1554Content_RE * ParsingEngine<B>::Parse_RemainingChildren (){
    15291555        Content_RE * c1 = Parse_Cp();
    15301556        Content_RE * r = c1;
     
    15931619
    15941620template <class B>
    1595 inline Content_RE * ParsingEngine<B>::Parse_Cp (){
     1621Content_RE * ParsingEngine<B>::Parse_Cp (){
    15961622        if (AtChar<B::Base,'('>(cur())){
    15971623                Advance(1);
     
    16201646
    16211647template <class B>
    1622 inline void ParsingEngine<B>::Parse_AttlistDecl (){
     1648void ParsingEngine<B>::Parse_AttlistDecl (){
    16231649       
    16241650        int old_abspos;
     
    17071733
    17081734template <class B>
    1709 inline void ParsingEngine<B>::Parse_Notation (ATT_info * this_info){
     1735void ParsingEngine<B>::Parse_Notation (ATT_info * this_info){
    17101736
    17111737        if(AtChar<B::Base,'('>(cur()))
     
    17401766
    17411767template <class B>
    1742 inline void ParsingEngine<B>::Parse_Enumeration (ATT_info * this_info){
     1768void ParsingEngine<B>::Parse_Enumeration (ATT_info * this_info){
    17431769
    17441770        int enumCount=0;
     
    17761802
    17771803template <class B>
    1778 inline void ParsingEngine<B>::Parse_DefaultDecl (ATT_info * this_info){
     1804void ParsingEngine<B>::Parse_DefaultDecl (ATT_info * this_info){
    17791805        if(at_REQUIRED<B::Base>(cur())){
    17801806                Advance(9);
     
    18081834
    18091835template <class B>
    1810 inline void ParsingEngine<B>::Parse_Entitydecl (){
     1836void ParsingEngine<B>::Parse_Entitydecl (){
    18111837       
    18121838        int name_start;
     
    18941920
    18951921template <class B>
    1896 inline void ParsingEngine<B>::Parse_Notationdecl (){
     1922void ParsingEngine<B>::Parse_Notationdecl (){
    18971923
    18981924        int old_abspos;
     
    19311957
    19321958template <class B>
    1933 inline void ParsingEngine<B>::Parse_AttValue(){
     1959void ParsingEngine<B>::Parse_AttValue(){
    19341960       
    19351961        int     quoteCh = cur()[0];
     
    19571983
    19581984template <class B>
    1959 inline void ParsingEngine<B>::Parse_GEntityValue(GEntity_info * this_info){
     1985void ParsingEngine<B>::Parse_GEntityValue(GEntity_info * this_info){
    19601986       
    19611987        int     quoteCh = cur()[0];
     
    19932019
    19942020template <class B>
    1995 inline char * ParsingEngine<B>::Replace_EntityRef(bool& is_simple){
     2021char * ParsingEngine<B>::Replace_EntityRef(bool& is_simple){
    19962022        Advance(1);
    19972023        int nameID = Parse_Name();
     
    20122038
    20132039template <class B>
    2014 inline void ParsingEngine<B>::Parse_PEntityValue(PEntity_info * this_info){
     2040void ParsingEngine<B>::Parse_PEntityValue(PEntity_info * this_info){
    20152041        fprintf(stderr,"parsing of parameter entity value has not been completed yet.\n");
    20162042        exit(-1);
     
    20182044
    20192045template <class B>
    2020 inline char * ParsingEngine<B>::Replace_CharRef(){
     2046char * ParsingEngine<B>::Replace_CharRef(){
    20212047        Advance(2);
    20222048        fprintf(stderr,"Replacement of Character Reference has not been completed yet.\n");
     
    20252051
    20262052template <class B>
    2027 inline void ParsingEngine<B>::Parse_Prolog(){
     2053void ParsingEngine<B>::Parse_Prolog(){
    20282054        ScanTo(NonWS);
    20292055        int old_pos = AbsPos();
     
    20522078
    20532079template <class B>
    2054 inline void ParsingEngine<B>::Parse_ExtSubsetDecl() {
     2080void ParsingEngine<B>::Parse_ExtSubsetDecl() {
    20552081        ScanTo(NonWS);
    20562082        int start_pos=AbsPos();
     
    22432269
    22442270template <class B>
    2245 inline int ParsingEngine<B>::Parse_ValidElement() {
     2271int ParsingEngine<B>::Parse_ValidElement() {
    22462272        bool is_emptyStartTag = false;
    22472273        int nameID = Parse_ValidStartTag(is_emptyStartTag);
     
    22912317
    22922318template <class B>
    2293 inline void ParsingEngine<B>::Parse_ValidContent(CM_RegExp * cre, int & cur_state) {
     2319void ParsingEngine<B>::Parse_ValidContent(CM_RegExp * cre, int & cur_state) {
    22942320        do {
    22952321                ScanTo(NonWS);
     
    23362362
    23372363template <class B>
    2338 inline void ParsingEngine<B>::Parse_AnyContent() {
     2364void ParsingEngine<B>::Parse_AnyContent() {
    23392365        do {
    23402366                text_or_markup_start = AbsPos();
     
    23872413}
    23882414template <class B>
    2389 inline void ParsingEngine<B>::Parse_MixedContent(symbol_set_t elems) {
     2415void ParsingEngine<B>::Parse_MixedContent(symbol_set_t elems) {
    23902416        do {
    23912417                text_or_markup_start = AbsPos();
     
    25222548
    25232549template <class B>
    2524 inline void ParsingEngine<B>::Parse_DocumentContent() {
     2550void ParsingEngine<B>::Parse_DocumentContent() {
    25252551#if (VALIDATION_MODE == ON)
    25262552        int cur_state = 0;
Note: See TracChangeset for help on using the changeset viewer.