summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-01-26 00:12:35 +0000
committerJeremy Allison <jra@samba.org>2000-01-26 00:12:35 +0000
commitd867b86721e988dee56d5e9382b32c870ccb2790 (patch)
treea19b4985a60d194abe083f9b0a6260c0c090b232 /source3
parentb5e7e4277d87c9eaa663f92c081a869b34170380 (diff)
downloadsamba-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')
-rw-r--r--source3/client/clitar.c8
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/include/smb.h5
-rw-r--r--source3/lib/kanji.c23
-rw-r--r--source3/lib/util_str.c74
-rw-r--r--source3/lib/util_unistr.c6
-rw-r--r--source3/param/params.c2
-rw-r--r--source3/smbd/mangle.c8
-rw-r--r--source3/smbd/reply.c2
9 files changed, 76 insertions, 53 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index f50c4b4288..d71eff1c9e 100644
--- a/source3/client/clitar.c
+++ b/source3/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/source3/include/proto.h b/source3/include/proto.h
index aa6e4104c1..03fc5b1353 100644
--- a/source3/include/proto.h
+++ b/source3/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/source3/include/smb.h b/source3/include/smb.h
index 58c43e76c7..6f0e16e869 100644
--- a/source3/include/smb.h
+++ b/source3/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/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);
/*
diff --git a/source3/param/params.c b/source3/param/params.c
index 944bc3d1b4..3ecdcdc92b 100644
--- a/source3/param/params.c
+++ b/source3/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/source3/smbd/mangle.c b/source3/smbd/mangle.c
index 4c306ad00f..e47bcd896f 100644
--- a/source3/smbd/mangle.c
+++ b/source3/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/source3/smbd/reply.c b/source3/smbd/reply.c
index d15a26b20c..d1ccda1750 100644
--- a/source3/smbd/reply.c
+++ b/source3/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;
}