Ignore:
Timestamp:
Nov 22, 2005 11:51:50 PM (17 years ago)
Author:
bennylp
Message:

More optimizations for msg parser etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/print_util.h

    r65 r77  
    2020#define __PJSIP_PRINT_H__ 
    2121 
    22 /* Minimum space left in the buffer */ 
    23 #define MIN_SPACE       10 
    24  
    2522#define copy_advance_check(buf,str)   \ 
    2623        do { \ 
    27             if ((str).slen+MIN_SPACE >= (endbuf-buf)) return -1;        \ 
     24            if ((str).slen >= (endbuf-buf)) return -1;  \ 
    2825            pj_memcpy(buf, (str).ptr, (str).slen); \ 
    2926            buf += (str).slen; \ 
    3027        } while (0) 
    31  
    32 /* 
    33 static char *imp_copy_advance_pair(char *buf, char *endbuf, const char *str1, int len1, const pj_str_t *str2) 
    34 { 
    35     if (str2->slen) { 
    36         int printed = len1+str2->slen; 
    37         if (printed+MIN_SPACE >= (endbuf-buf)) return NULL; 
    38         pj_memcpy(buf,str1,len1); 
    39         pj_memcpy(buf+len1, str2->ptr, str2->slen); 
    40         return buf + printed; 
    41     } else 
    42         return buf; 
    43 } 
    44 */ 
    4528 
    4629#define copy_advance_pair_check(buf,str1,len1,str2)   \ 
     
    4831            if (str2.slen) { \ 
    4932                printed = len1+str2.slen; \ 
    50                 if (printed+MIN_SPACE >= (endbuf-buf)) return -1;       \ 
     33                if (printed >= (endbuf-buf)) return -1; \ 
    5134                pj_memcpy(buf,str1,len1); \ 
    5235                pj_memcpy(buf+len1, str2.ptr, str2.slen); \ 
     
    5437            } \ 
    5538        } while (0) 
    56 /* 
    57 #define copy_advance_pair(buf,str1,len1,str2)   \ 
    58         do { \ 
    59             buf = imp_copy_advance_pair(buf, endbuf, str1, len1, &str2); \ 
    60             if (buf == NULL) return -1; \ 
    61         } while (0) 
    62 */ 
    6339 
    6440#define copy_advance_pair_quote_check(buf,str1,len1,str2,quotebegin,quoteend) \ 
     
    6642            if (str2.slen) { \ 
    6743                printed = len1+str2.slen+2; \ 
    68                 if (printed+MIN_SPACE >= (endbuf-buf)) return -1;       \ 
     44                if (printed >= (endbuf-buf)) return -1; \ 
    6945                pj_memcpy(buf,str1,len1); \ 
    7046                *(buf+len1)=quotebegin; \ 
     
    7753#define copy_advance_pair_escape(buf,str1,len1,str2,unres)      \ 
    7854        do { \ 
    79             if (str2.slen) { \ 
    80                 pj_ssize_t esc_len; \ 
    81                 if (len1+str2.slen+MIN_SPACE >= (endbuf-buf)) return -1; \ 
    82                 pj_memcpy(buf,str1,len1); \ 
    83                 buf += len1; \ 
    84                 esc_len=pj_strncpy2_escape(buf, &str2, (endbuf-buf), &unres); \ 
    85                 if (esc_len < 0) return -1; \ 
    86                 buf += esc_len; \ 
    87                 if (endbuf-buf < MIN_SPACE) return -1; \ 
    88             } \ 
     55          if (str2.slen) { \ 
     56            if (len1+str2.slen >= (endbuf-buf)) return -1; \ 
     57            pj_memcpy(buf,str1,len1); \ 
     58            printed=pj_strncpy2_escape(buf,&str2,(endbuf-buf-len1),&unres);\ 
     59            if (printed < 0) return -1; \ 
     60            buf += (printed+len1); \ 
     61          } \ 
    8962        } while (0) 
    9063 
     
    9871#define copy_advance_escape(buf,str,unres)    \ 
    9972        do { \ 
    100             pj_ssize_t len = \ 
     73            printed = \ 
    10174                pj_strncpy2_escape(buf, &(str), (endbuf-buf), &(unres)); \ 
    102             if (len < 0) return -1; \ 
    103             buf += len; \ 
    104             if (endbuf-buf < MIN_SPACE) return -1; \ 
     75            if (printed < 0) return -1; \ 
     76            buf += printed; \ 
    10577        } while (0) 
    10678 
     
    11890#define copy_advance_pair_quote_cond(buf,str1,len1,str2,quotebegin,quoteend) \ 
    11991        do {    \ 
    120             if (str2.slen && *str2.ptr!=quotebegin) \ 
    121                 copy_advance_pair_quote(buf,str1,len1,str2,quotebegin,quoteend); \ 
    122             else \ 
    123                 copy_advance_pair(buf,str1,len1,str2); \ 
     92          if (str2.slen && *str2.ptr!=quotebegin) \ 
     93            copy_advance_pair_quote(buf,str1,len1,str2,quotebegin,quoteend); \ 
     94          else \ 
     95            copy_advance_pair(buf,str1,len1,str2); \ 
    12496        } while (0) 
    12597 
Note: See TracChangeset for help on using the changeset viewer.