Ignore:
Timestamp:
Nov 21, 2005 5:06:21 PM (18 years ago)
Author:
bennylp
Message:

Scanner optimization and added cis_uint backend

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/scanner.c

    r65 r73  
    2222#include <pj/os.h> 
    2323#include <pj/errno.h> 
     24#include <pj/assert.h> 
    2425 
    2526#define PJ_SCAN_IS_SPACE(c)     ((c)==' ' || (c)=='\t') 
     
    2829 
    2930 
     31#if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0 
     32#  include "scanner_cis_bitwise.c" 
     33#else 
     34#  include "scanner_cis_uint.c" 
     35#endif 
     36 
     37 
    3038static void pj_scan_syntax_err(pj_scanner *scanner) 
    3139{ 
     
    3341} 
    3442 
    35 PJ_DEF(void) pj_cis_buf_init( pj_cis_buf_t *cis_buf) 
    36 { 
    37     pj_memset(cis_buf->cis_buf, 0, sizeof(cis_buf->cis_buf)); 
    38     cis_buf->use_mask = 0; 
    39 } 
    40  
    41 PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis) 
    42 { 
    43     unsigned i; 
    44  
    45     cis->cis_buf = cis_buf->cis_buf; 
    46  
    47     for (i=0; i<PJ_CIS_MAX_INDEX; ++i) { 
    48         if ((cis_buf->use_mask & (1 << i)) == 0) { 
    49             cis->cis_id = i; 
    50             cis_buf->use_mask |= (1 << i); 
    51             return PJ_SUCCESS; 
    52         } 
    53     } 
    54  
    55     cis->cis_id = PJ_CIS_MAX_INDEX; 
    56     return PJ_ETOOMANY; 
    57 } 
    58  
    59 PJ_DEF(pj_status_t) pj_cis_dup( pj_cis_t *new_cis, pj_cis_t *existing) 
    60 { 
    61     pj_status_t status; 
    62     unsigned i; 
    63  
    64     /* Warning: typecasting here! */ 
    65     status = pj_cis_init((pj_cis_buf_t*)existing->cis_buf, new_cis); 
    66     if (status != PJ_SUCCESS) 
    67         return status; 
    68  
    69     for (i=0; i<256; ++i) { 
    70         if (PJ_CIS_ISSET(existing, i)) 
    71             PJ_CIS_SET(new_cis, i); 
    72         else 
    73             PJ_CIS_CLR(new_cis, i); 
    74     } 
    75  
    76     return PJ_SUCCESS; 
    77 } 
    7843 
    7944PJ_DEF(void) pj_cis_add_range(pj_cis_t *cis, int cstart, int cend) 
    8045{ 
     46    /* Can not set zero. This is the requirement of the parser. */ 
     47    pj_assert(cstart > 0); 
     48 
    8149    while (cstart != cend) { 
    8250        PJ_CIS_SET(cis, cstart); 
     
    12391{ 
    12492    unsigned i; 
    125     for (i=0; i<256; ++i) { 
     93    /* Can not set zero. This is the requirement of the parser. */ 
     94    for (i=1; i<256; ++i) { 
    12695        if (PJ_CIS_ISSET(cis,i)) 
    12796            PJ_CIS_CLR(cis,i); 
     
    285254    PJ_CHECK_STACK(); 
    286255 
     256    pj_assert(pj_cis_match(spec,0)==0); 
     257 
    287258    if (pj_scan_is_eof(scanner) || !pj_cis_match(spec, *s)) { 
    288259        pj_scan_syntax_err(scanner); 
     
    292263    do { 
    293264        ++s; 
    294     } while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)); 
     265    } while (pj_cis_match(spec, *s)); 
     266    /* No need to check EOF here (PJ_SCAN_CHECK_EOF(s)) because 
     267     * buffer is NULL terminated and pj_cis_match(spec,0) should be 
     268     * false. 
     269     */ 
    295270 
    296271    pj_strset3(out, scanner->curptr, s); 
Note: See TracChangeset for help on using the changeset viewer.