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 | d867b86721e988dee56d5e9382b32c870ccb2790 (patch) | |
tree | a19b4985a60d194abe083f9b0a6260c0c090b232 /source3/lib | |
parent | b5e7e4277d87c9eaa663f92c081a869b34170380 (diff) | |
download | samba-d867b86721e988dee56d5e9382b32c870ccb2790.tar.gz samba-d867b86721e988dee56d5e9382b32c870ccb2790.tar.bz2 samba-d867b86721e988dee56d5e9382b32c870ccb2790.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.
(This used to be commit e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/kanji.c | 23 | ||||
-rw-r--r-- | source3/lib/util_str.c | 74 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 6 |
3 files changed, 61 insertions, 42 deletions
diff --git a/source3/lib/kanji.c b/source3/lib/kanji.c index 1983bb1161..43b22c19cc 100644 --- a/source3/lib/kanji.c +++ b/source3/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/source3/lib/util_str.c b/source3/lib/util_str.c index b16de3efda..d703670860 100644 --- a/source3/lib/util_str.c +++ b/source3/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/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 5e7076d5df..a512f68acc 100644 --- a/source3/lib/util_unistr.c +++ b/source3/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); /* |