Changeset 4123

Show
Ignore:
Timestamp:
08/31/06 05:36:09 (8 years ago)
Author:
mmh
Message:

Remove %option yylineno and add/modify rules to count lines explicitly;
this is a performance win. Tweak some other rules for potential speedups
also (e.g. use {BLANK}+ in place of {BLANK} to eat as much whitespace as
possible in a single shot).

This is all straight out of the Performance section of the Flex manual.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/scanner-opt-branch/lib/conf-lex.l

    r4122 r4123  
    3333 
    3434char sensors_lex_error[100]; 
     35 
     36int sensors_yylineno; 
    3537 
    3638#define buffer_malloc() sensors_malloc_array(&buffer,&buffer_count,\ 
     
    5153%option nodefault 
    5254%option noyywrap 
    53 %option yylineno 
    5455%option nounput 
    5556 
     
    6566 /* Any whitespace-like character */ 
    6667 
    67 BLANK           [[:space:]] 
     68BLANK           [ \f\t\v] 
    6869 
    6970IDCHAR          [[:alnum:]_] 
     
    8586 
    8687 
    87  /* End of line: It may be the end of this line. Same for End of file. */ 
    88  
    89 <MIDDLE>\n      | 
    90 <MIDDLE><<EOF>> { 
    91                   BEGIN(INITIAL); 
     88<MIDDLE>\n      { /* newline here sends EOL token to parser */ 
     89                  BEGIN(INITIAL); 
     90                  sensors_yylineno++; 
    9291                  return EOL; 
    9392                } 
    9493 
    95  /* 
    96   * We want to match any blank, except End of line; that is why we have to 
    97   * match whitespace one by one! 
    98   */ 
    99  
    100 {BLANK}         /* Eat up a blank */ 
    101  
    102  /* Escaped End of line: eat and be happy */ 
    103  
    104 <MIDDLE>\\\n    /* Eat this! */ 
    105  
    106  /* 
    107   * Remove a comment; we do not change the state, 
    108   * this is done when the \n is eaten 
    109   */ 
    110  
    111 #[^\n]*         /* Eat this! */ 
     94<MIDDLE><<EOF>> { /* EOF here sends EOL token to parser also */ 
     95                  BEGIN(INITIAL); 
     96                  return EOL; 
     97                } 
     98 
     99{BLANK}+ ;        /* eat as many blanks as possible at once */ 
     100 
     101{BLANK}*\n      { /* eat a bare newline (possibly preceded by blanks) */ 
     102                  sensors_yylineno++; 
     103                } 
     104 
     105<MIDDLE>\\{BLANK}*\n { /* eat an escaped newline with no state change */ 
     106                  sensors_yylineno++; 
     107                } 
     108 
     109<MIDDLE>#.*     ; /* eat the rest of the line after comment char */ 
     110 
     111<MIDDLE>#.*\n   { /* eat the rest of the line after comment char */ 
     112                  BEGIN(INITIAL); 
     113                  sensors_yylineno++; 
     114                  return EOL; 
     115                } 
     116 
     117#.*             ; /* eat the rest of the line after comment char */ 
     118 
     119#.*\n           { /* eat the rest of the line after comment char */ 
     120                  sensors_yylineno++; 
     121                } 
    112122 
    113123 /* Some keywords at the beginning of lines */ 
     
    291301 
    292302        sensors_yy_switch_to_buffer(scan_buf); 
     303        sensors_yylineno = 1; 
    293304        return 0; 
    294305}