diff options
author | Jeremy Allison <jra@samba.org> | 2000-01-26 00:12:35 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2000-01-26 00:12:35 +0000 |
commit | e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c (patch) | |
tree | a074521709f35ce1d63acbaf6e0a1cebe38b12e1 /source | |
parent | fc0219c7cc4b83e6db17d5b3be70d74fd7971089 (diff) | |
download | samba-e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c.tar.gz samba-e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c.tar.xz samba-e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c.zip |
Second set of inline optimisation fixes from Ying Chen <ying@almaden.ibm.com>.
Stop makeing function calls for every use of skip_multibyte_char. This function
is called several *million* times during a NetBench run :-).
Jeremy.
Diffstat (limited to 'source')
-rw-r--r-- | source/client/clitar.c | 8 | ||||
-rw-r--r-- | source/include/proto.h | 1 | ||||
-rw-r--r-- | source/include/smb.h | 5 | ||||
-rw-r--r-- | source/lib/kanji.c | 23 | ||||
-rw-r--r-- | source/lib/util_str.c | 74 | ||||
-rw-r--r-- | source/lib/util_unistr.c | 6 | ||||
-rw-r--r-- | source/param/params.c | 2 | ||||
-rw-r--r-- | source/smbd/mangle.c | 8 | ||||
-rw-r--r-- | source/smbd/reply.c | 2 |
9 files changed, 76 insertions, 53 deletions
diff --git a/source/client/clitar.c b/source/client/clitar.c index f50c4b42882..d71eff1c9e2 100644 --- a/source/client/clitar.c +++ b/source/client/clitar.c @@ -427,8 +427,8 @@ static void fixtarname(char *tptr, char *fp, int l) *tptr++='.'; while (l > 0) { - int skip; - if((skip = skip_multibyte_char( *fp)) != 0) { + int skip = get_character_len(*fp); + if(skip != 0) { if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; @@ -885,8 +885,8 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) } while (l > 0) { - int skip; - if(( skip = skip_multibyte_char( *fp )) != 0) { + int skip = get_character_len(*fp); + if(skip != 0) { if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; diff --git a/source/include/proto.h b/source/include/proto.h index aa6e4104c10..03fc5b13536 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -119,7 +119,6 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces); /*The following definitions come from lib/kanji.c */ void interpret_coding_system(char *str); -BOOL is_multibyte_codepage(void); void initialize_multibyte_vectors( int client_codepage); /*The following definitions come from lib/md4.c */ diff --git a/source/include/smb.h b/source/include/smb.h index 58c43e76c76..6f0e16e8691 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -1699,6 +1699,11 @@ enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1}; #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE #endif /* KANJI */ +/* Global val set if multibyte codepage. */ +extern int global_is_multibyte_codepage; + +#define get_character_len(x) (global_is_multibyte_codepage ? skip_multibyte_char((x)) : 0) + /* * Size of buffer to use when moving files across filesystems. */ diff --git a/source/lib/kanji.c b/source/lib/kanji.c index 1983bb11619..43b22c19cce 100644 --- a/source/lib/kanji.c +++ b/source/lib/kanji.c @@ -80,6 +80,8 @@ int (*is_multibyte_char_1)(char) = is_kanji_multibyte_char_1; #endif /* KANJI */ +BOOL global_is_multibyte_codepage = False; + /* jis si/so sequence */ static char jis_kso = JIS_KSO; static char jis_ksi = JIS_KSI; @@ -1163,17 +1165,6 @@ static BOOL not_multibyte_char_1(char c) } /******************************************************************* - Function to determine if we are in a multibyte code page. -*******************************************************************/ - -static BOOL is_multibyte_codepage_val = False; - -BOOL is_multibyte_codepage(void) -{ - return is_multibyte_codepage_val; -} - -/******************************************************************* Setup the function pointers for the functions that are replaced when multi-byte codepages are used. @@ -1193,7 +1184,7 @@ void initialize_multibyte_vectors( int client_codepage) multibyte_strtok = sj_strtok; _skip_multibyte_char = skip_kanji_multibyte_char; is_multibyte_char_1 = is_kanji_multibyte_char_1; - is_multibyte_codepage_val = True; + global_is_multibyte_codepage = True; break; case HANGUL_CODEPAGE: multibyte_strchr = generic_multibyte_strchr; @@ -1202,7 +1193,7 @@ void initialize_multibyte_vectors( int client_codepage) multibyte_strtok = generic_multibyte_strtok; _skip_multibyte_char = skip_generic_multibyte_char; is_multibyte_char_1 = hangul_is_multibyte_char_1; - is_multibyte_codepage_val = True; + global_is_multibyte_codepage = True; break; case BIG5_CODEPAGE: multibyte_strchr = generic_multibyte_strchr; @@ -1211,7 +1202,7 @@ void initialize_multibyte_vectors( int client_codepage) multibyte_strtok = generic_multibyte_strtok; _skip_multibyte_char = skip_generic_multibyte_char; is_multibyte_char_1 = big5_is_multibyte_char_1; - is_multibyte_codepage_val = True; + global_is_multibyte_codepage = True; break; case SIMPLIFIED_CHINESE_CODEPAGE: multibyte_strchr = generic_multibyte_strchr; @@ -1220,7 +1211,7 @@ void initialize_multibyte_vectors( int client_codepage) multibyte_strtok = generic_multibyte_strtok; _skip_multibyte_char = skip_generic_multibyte_char; is_multibyte_char_1 = simpch_is_multibyte_char_1; - is_multibyte_codepage_val = True; + global_is_multibyte_codepage = True; break; /* * Single char size code page. @@ -1232,7 +1223,7 @@ void initialize_multibyte_vectors( int client_codepage) multibyte_strtok = (char *(*)(char *, const char *)) strtok; _skip_multibyte_char = skip_non_multibyte_char; is_multibyte_char_1 = not_multibyte_char_1; - is_multibyte_codepage_val = False; + global_is_multibyte_codepage = False; break; } } diff --git a/source/lib/util_str.c b/source/lib/util_str.c index b16de3efda4..d703670860b 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -343,7 +343,7 @@ void strlower(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else @@ -396,7 +396,7 @@ void strupper(char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else @@ -440,17 +440,29 @@ BOOL strisnormal(char *s) void string_replace(char *s,char oldc,char newc) { size_t skip; - while (*s) - { - skip = skip_multibyte_char( *s ); - if( skip != 0 ) - s += skip; - else - { + + /* + * sbcs optimization. + */ + if(!global_is_multibyte_codepage) { + while (*s) { if (oldc == *s) *s = newc; s++; } + } else { + while (*s) + { + skip = get_character_len( *s ); + if( skip != 0 ) + s += skip; + else + { + if (oldc == *s) + *s = newc; + s++; + } + } } } @@ -476,10 +488,17 @@ size_t str_charnum(const char *s) { size_t len = 0; - while (*s != '\0') { - int skip = skip_multibyte_char(*s); - s += (skip ? skip : 1); - len++; + /* + * sbcs optimization. + */ + if(!global_is_multibyte_codepage) { + return strlen(s); + } else { + while (*s != '\0') { + int skip = get_character_len(*s); + s += (skip ? skip : 1); + len++; + } } return len; } @@ -518,7 +537,7 @@ BOOL trim_string(char *s,const char *front,const char *back) if(back_len) { - if(!is_multibyte_codepage()) + if(!global_is_multibyte_codepage) { s_len = strlen(s); while ((s_len >= back_len) && @@ -552,11 +571,20 @@ BOOL trim_string(char *s,const char *front,const char *back) size_t charcount = 0; char *mbp = s; - while(charcount < (mb_s_len - mb_back_len)) - { - size_t skip = skip_multibyte_char(*mbp); - mbp += (skip ? skip : 1); - charcount++; + /* + * sbcs optimization. + */ + if(!global_is_multibyte_codepage) { + while(charcount < (mb_s_len - mb_back_len)) { + mbp += 1; + charcount++; + } + } else { + while(charcount < (mb_s_len - mb_back_len)) { + size_t skip = skip_multibyte_char(*mbp); + mbp += (skip ? skip : 1); + charcount++; + } } /* @@ -615,7 +643,7 @@ BOOL strhasupper(const char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else { @@ -670,7 +698,7 @@ BOOL strhaslower(const char *s) else #endif /* KANJI_WIN95_COMPATIBILITY */ { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else { @@ -720,7 +748,7 @@ size_t count_chars(const char *s,char c) { while (*s) { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else { @@ -774,7 +802,7 @@ BOOL str_is_all(const char *s,char c) { while (*s) { - size_t skip = skip_multibyte_char( *s ); + size_t skip = get_character_len( *s ); if( skip != 0 ) s += skip; else { diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index 5e7076d5df6..a512f68acc0 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -54,7 +54,7 @@ int dos_PutUniCode(char *dst,const char *src, ssize_t len) { int ret = 0; while (*src && (len > 2)) { - size_t skip = skip_multibyte_char(*src); + size_t skip = get_character_len(*src); smb_ucs2_t val = (*src & 0xff); /* @@ -272,7 +272,7 @@ size_t dos_struni2(char *dst, const char *src, size_t max_len) if (src != NULL) { for (; *src && len < max_len-2; len++, dst +=2) { - size_t skip = skip_multibyte_char(*src); + size_t skip = get_character_len(*src); smb_ucs2_t val = (*src & 0xff); /* @@ -615,7 +615,7 @@ smb_ucs2_t *multibyte_to_unicode(smb_ucs2_t *dst, const char *src, dst_len /= sizeof(smb_ucs2_t); /* Convert to smb_ucs2_t units. */ for(i = 0; (i < (dst_len - 1)) && src[i];) { - size_t skip = skip_multibyte_char(*src); + size_t skip = get_character_len(*src); smb_ucs2_t val = (*src & 0xff); /* diff --git a/source/param/params.c b/source/param/params.c index 944bc3d1b43..3ecdcdc92b3 100644 --- a/source/param/params.c +++ b/source/param/params.c @@ -182,7 +182,7 @@ static int Continuation( char *line, int pos ) /* we should recognize if `\` is part of a multibyte character or not. */ while(pos2 <= pos) { size_t skip = 0; - skip = skip_multibyte_char(line[pos2]); + skip = get_character_len(line[pos2]); if (skip) { pos2 += skip; } else if (pos == pos2) { diff --git a/source/smbd/mangle.c b/source/smbd/mangle.c index 4c306ad00f8..e47bcd896f6 100644 --- a/source/smbd/mangle.c +++ b/source/smbd/mangle.c @@ -255,7 +255,7 @@ static BOOL is_illegal_name( char *name ) s = (unsigned char *)name; while( *s ) { - skip = skip_multibyte_char( *s ); + skip = get_character_len( *s ); if( skip != 0 ) { s += skip; @@ -374,7 +374,7 @@ BOOL is_8_3( char *fname, BOOL check_case ) dot_pos = NULL; while( *p ) { - if( (skip = skip_multibyte_char( *p )) != 0 ) + if( (skip = get_character_len( *p )) != 0 ) p += skip; else { @@ -878,7 +878,7 @@ void mangle_name_83( char *s) *p++ = 0; while( *p && extlen < 3 ) { - skip = skip_multibyte_char( *p ); + skip = get_character_len( *p ); switch( skip ) { case 2: @@ -912,7 +912,7 @@ void mangle_name_83( char *s) while( *p && baselen < 5 ) { - skip = skip_multibyte_char(*p); + skip = get_character_len(*p); switch( skip ) { case 2: diff --git a/source/smbd/reply.c b/source/smbd/reply.c index d15a26b20ce..d1ccda1750a 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -1334,7 +1334,7 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size p = mask; while(*p) { - if((skip = skip_multibyte_char( *p )) != 0 ) + if((skip = get_character_len( *p )) != 0 ) { p += skip; } |