From c615ebed6e3d273a682806b952d543e834e5630d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 13 May 2011 20:21:30 +0200 Subject: s3-lib Replace StrCaseCmp() with strcasecmp_m() strcasecmp_m() never needs to call to talloc, and via next_codepoint() still has an ASCII fast-path bypassing iconv() calls. Andrew Bartlett --- source3/lib/adt_tree.c | 4 +-- source3/lib/filename_util.c | 2 +- source3/lib/ms_fnmatch.c | 2 +- source3/lib/smbldap.c | 4 +-- source3/lib/tldap_util.c | 2 +- source3/lib/util.c | 4 +-- source3/lib/util_str.c | 85 +-------------------------------------------- 7 files changed, 10 insertions(+), 93 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/adt_tree.c b/source3/lib/adt_tree.c index 6d481613c7..de7f2d2637 100644 --- a/source3/lib/adt_tree.c +++ b/source3/lib/adt_tree.c @@ -134,7 +134,7 @@ static struct tree_node *pathtree_birth_child(struct tree_node *node, /* the strings should never match assuming that we have called pathtree_find_child() first */ - if ( StrCaseCmp( infant->key, node->children[i-1]->key ) > 0 ) { + if ( strcasecmp_m( infant->key, node->children[i-1]->key ) > 0 ) { DEBUG(11,("pathtree_birth_child: storing infant in i == [%d]\n", i)); node->children[i] = infant; @@ -183,7 +183,7 @@ static struct tree_node *pathtree_find_child(struct tree_node *node, DEBUG(11,("pathtree_find_child: child key => [%s]\n", node->children[i]->key)); - result = StrCaseCmp( node->children[i]->key, key ); + result = strcasecmp_m( node->children[i]->key, key ); if ( result == 0 ) next = node->children[i]; diff --git a/source3/lib/filename_util.c b/source3/lib/filename_util.c index d24660c981..2405183d53 100644 --- a/source3/lib/filename_util.c +++ b/source3/lib/filename_util.c @@ -202,5 +202,5 @@ bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname) return false; } - return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0; + return strcasecmp_m(smb_fname->stream_name, "::$DATA") == 0; } diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c index 272355b7d2..f02354bfd7 100644 --- a/source3/lib/ms_fnmatch.c +++ b/source3/lib/ms_fnmatch.c @@ -166,7 +166,7 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern, if (is_case_sensitive) { return strcmp(pattern, string); } else { - return StrCaseCmp(pattern, string); + return strcasecmp_m(pattern, string); } } diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index d7d06e9e08..fe383663d7 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -405,7 +405,7 @@ ATTRIB_MAP_ENTRY sidmap_attr_list[] = { return NULL; } - if (StrCaseCmp(tmp, result) < 0) { + if (strcasecmp_m(tmp, result) < 0) { TALLOC_FREE(result); result = tmp; } else { @@ -654,7 +654,7 @@ static void smbldap_make_mod_internal(LDAP *ldap_struct, LDAPMessage *existing, equal = (newblob && (data_blob_cmp(&oldblob, newblob) == 0)); } else { /* all of our string attributes are case insensitive */ - equal = (newval && (StrCaseCmp(oldval, newval) == 0)); + equal = (newval && (strcasecmp_m(oldval, newval) == 0)); } if (equal) { diff --git a/source3/lib/tldap_util.c b/source3/lib/tldap_util.c index e4cb5f040b..6b9f912e27 100644 --- a/source3/lib/tldap_util.c +++ b/source3/lib/tldap_util.c @@ -300,7 +300,7 @@ static int compare_utf8_blobs(const DATA_BLOB *d1, const DATA_BLOB *d2) TALLOC_FREE(s1); return 0; } - ret = StrCaseCmp(s1, s2); + ret = strcasecmp_m(s1, s2); TALLOC_FREE(s2); TALLOC_FREE(s1); return ret; diff --git a/source3/lib/util.c b/source3/lib/util.c index 8d90569863..ee696461c6 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1299,7 +1299,7 @@ bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensit } } else { if((case_sensitive && (strcmp(last_component, namelist->name) == 0))|| - (!case_sensitive && (StrCaseCmp(last_component, namelist->name) == 0))) { + (!case_sensitive && (strcasecmp_m(last_component, namelist->name) == 0))) { DEBUG(8,("is_in_path: match succeeded\n")); return True; } @@ -2203,7 +2203,7 @@ bool name_to_fqdn(fstring fqdn, const char *name) } } } - if (full && (StrCaseCmp(full, "localhost.localdomain") == 0)) { + if (full && (strcasecmp_m(full, "localhost.localdomain") == 0)) { DEBUG(1, ("WARNING: your /etc/hosts file may be broken!\n")); DEBUGADD(1, (" Specifing the machine hostname for address 127.0.0.1 may lead\n")); DEBUGADD(1, (" to Kerberos authentication problems as localhost.localdomain\n")); diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 3dc73d9b8e..ee36930fd1 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -35,89 +35,6 @@ const char toupper_ascii_fast_table[128] = { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f }; -/** - * Case insensitive string compararison. - * - * iconv does not directly give us a way to compare strings in - * arbitrary unix character sets -- all we can is convert and then - * compare. This is expensive. - * - * As an optimization, we do a first pass that considers only the - * prefix of the strings that is entirely 7-bit. Within this, we - * check whether they have the same value. - * - * Hopefully this will often give the answer without needing to copy. - * In particular it should speed comparisons to literal ascii strings - * or comparisons of strings that are "obviously" different. - * - * If we find a non-ascii character we fall back to converting via - * iconv. - * - * This should never be slower than convering the whole thing, and - * often faster. - * - * A different optimization would be to compare for bitwise equality - * in the binary encoding. (It would be possible thought hairy to do - * both simultaneously.) But in that case if they turn out to be - * different, we'd need to restart the whole thing. - * - * Even better is to implement strcasecmp for each encoding and use a - * function pointer. - **/ -int StrCaseCmp(const char *s, const char *t) -{ - - const char *ps, *pt; - size_t size; - smb_ucs2_t *buffer_s, *buffer_t; - int ret; - - for (ps = s, pt = t; ; ps++, pt++) { - char us, ut; - - if (!*ps && !*pt) - return 0; /* both ended */ - else if (!*ps) - return -1; /* s is a prefix */ - else if (!*pt) - return +1; /* t is a prefix */ - else if ((*ps & 0x80) || (*pt & 0x80)) - /* not ascii anymore, do it the hard way - * from here on in */ - break; - - us = toupper_ascii_fast(*ps); - ut = toupper_ascii_fast(*pt); - if (us == ut) - continue; - else if (us < ut) - return -1; - else if (us > ut) - return +1; - } - - if (!push_ucs2_talloc(talloc_tos(), &buffer_s, ps, &size)) { - return strcmp(ps, pt); - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty - close */ - } - - if (!push_ucs2_talloc(talloc_tos(), &buffer_t, pt, &size)) { - TALLOC_FREE(buffer_s); - return strcmp(ps, pt); - /* Not quite the right answer, but finding the right one - under this failure case is expensive, and it's pretty - close */ - } - - ret = strcasecmp_w(buffer_s, buffer_t); - TALLOC_FREE(buffer_s); - TALLOC_FREE(buffer_t); - return ret; -} - - /** Case insensitive string compararison, length limited. **/ @@ -360,7 +277,7 @@ bool in_list(const char *s, const char *list, bool casesensitive) break; } } else { - if (StrCaseCmp(tok,s) == 0) { + if (strcasecmp_m(tok,s) == 0) { ret = true; break; } -- cgit