Changeset 73 for pjproject/trunk


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

Scanner optimization and added cis_uint backend

Location:
pjproject/trunk/pjlib-util
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/build/pjlib_util.dsp

    r65 r73  
    4242# PROP Target_Dir "" 
    4343# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    44 # ADD CPP /nologo /MD /W3 /GX /O2 /I "../include" /I "../../pjlib/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /YX /FD /c 
     44# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /Ob2 /I "../include" /I "../../pjlib/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /YX /FD /c 
    4545# ADD BASE RSC /l 0x409 /d "NDEBUG" 
    4646# ADD RSC /l 0x409 /d "NDEBUG" 
     
    9494# Begin Source File 
    9595 
     96SOURCE="..\src\pjlib-util\scanner_cis_bitwise.c" 
     97# PROP Exclude_From_Build 1 
     98# End Source File 
     99# Begin Source File 
     100 
     101SOURCE="..\src\pjlib-util\scanner_cis_uint.c" 
     102# PROP Exclude_From_Build 1 
     103# End Source File 
     104# Begin Source File 
     105 
    96106SOURCE="..\src\pjlib-util\string.c" 
    97107# End Source File 
     
    130140# Begin Source File 
    131141 
     142SOURCE="..\include\pjlib-util\scanner_cis_bitwise.h" 
     143# End Source File 
     144# Begin Source File 
     145 
     146SOURCE="..\include\pjlib-util\scanner_cis_uint.h" 
     147# End Source File 
     148# Begin Source File 
     149 
    132150SOURCE="..\include\pjlib-util\string.h" 
    133151# End Source File 
  • pjproject/trunk/pjlib-util/include/pjlib-util/scanner.h

    r65 r73  
    2727#include <pj/types.h> 
    2828 
     29/** 
     30 * Macro PJ_SCANNER_USE_BITWISE is defined and non-zero (by default yes) 
     31 * will enable the use of bitwise for character input specification (cis). 
     32 * This would save several kilobytes of .bss memory in the SIP parser. 
     33 */ 
     34#ifndef PJ_SCANNER_USE_BITWISE 
     35#  define PJ_SCANNER_USE_BITWISE   1 
     36#endif 
     37 
     38 
    2939PJ_BEGIN_DECL 
    3040 
     
    3747 * @{ 
    3848 */ 
    39  
    40 /** 
    41  * This describes the type of individual character specification in 
    42  * #pj_cis_buf_t. Basicly the number of bits here 
    43  */ 
    44 #ifndef PJ_CIS_ELEM_TYPE 
    45 #   define PJ_CIS_ELEM_TYPE pj_uint32_t 
     49#if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0 
     50#  include <pjlib-util/scanner_cis_bitwise.h> 
     51#else 
     52#  include <pjlib-util/scanner_cis_uint.h> 
    4653#endif 
    47  
    48 /** 
    49  * This describes the type of individual character specification in 
    50  * #pj_cis_buf_t. 
    51  */ 
    52 typedef PJ_CIS_ELEM_TYPE pj_cis_elem_t; 
    53  
    54 /** 
    55  * Maximum number of input specification in a buffer. 
    56  * Effectively this means the number of bits in pj_cis_elem_t. 
    57  */ 
    58 #define PJ_CIS_MAX_INDEX   (sizeof(pj_cis_elem_t) << 3) 
    59  
    60 /** 
    61  * The scanner input specification buffer. 
    62  */ 
    63 typedef struct pj_cis_buf_t 
    64 { 
    65     pj_cis_elem_t    cis_buf[256];  /**< Must be 256 (not 128)! */ 
    66     pj_cis_elem_t    use_mask;      /**< To keep used indexes.  */ 
    67 } pj_cis_buf_t; 
    68  
    69 /** 
    70  * Character input specification. 
    71  */ 
    72 typedef struct pj_cis_t 
    73 { 
    74     pj_cis_elem_t   *cis_buf;       /**< Pointer to buffer.     */ 
    75     int              cis_id;        /**< Id.                    */ 
    76 } pj_cis_t; 
    7754 
    7855/** 
     
    10784 */ 
    10885PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing); 
    109  
    110 /** 
    111  * Set the membership of the specified character. 
    112  * Note that this is a macro, and arguments may be evaluated more than once. 
    113  * 
    114  * @param cis       Pointer to character input specification. 
    115  * @param c         The character. 
    116  */ 
    117 #define PJ_CIS_SET(cis,c)   ((cis)->cis_buf[(c)] |= (1 << (cis)->cis_id)) 
    118  
    119 /** 
    120  * Remove the membership of the specified character. 
    121  * Note that this is a macro, and arguments may be evaluated more than once. 
    122  * 
    123  * @param cis       Pointer to character input specification. 
    124  * @param c         The character to be removed from the membership. 
    125  */ 
    126 #define PJ_CIS_CLR(cis,c)   ((cis)->cis_buf[c] &= ~(1 << (cis)->cis_id)) 
    127  
    128 /** 
    129  * Check the membership of the specified character. 
    130  * Note that this is a macro, and arguments may be evaluated more than once. 
    131  * 
    132  * @param cis       Pointer to character input specification. 
    133  * @param c         The character. 
    134  */ 
    135 #define PJ_CIS_ISSET(cis,c) ((cis)->cis_buf[c] & (1 << (cis)->cis_id)) 
    13686 
    13787/** 
  • pjproject/trunk/pjlib-util/src/pjlib-util-test/test.c

    r65 r73  
    7575        return test_inner(); 
    7676    } 
    77     PJ_DEFAULT { 
     77    PJ_CATCH_ANY { 
    7878        int id = PJ_GET_EXCEPTION(); 
    7979        PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",  
  • 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); 
  • pjproject/trunk/pjlib-util/src/pjlib-util/xml.c

    r65 r73  
    172172        node =  xml_parse_node(pool, &scanner); 
    173173    } 
    174     PJ_DEFAULT { 
     174    PJ_CATCH_ANY { 
    175175        PJ_LOG(4,(THIS_FILE, "Syntax error parsing XML in line %d column %d", 
    176176                  scanner.line, scanner.col)); 
Note: See TracChangeset for help on using the changeset viewer.