From: Stig Venaas Date: Mon, 25 Feb 2002 13:20:09 +0000 (+0000) Subject: Optimizing UTF8bvnormcmp() by adding flags that tells which arguments are X-Git-Tag: OPENLDAP_REL_ENG_2_MP~392 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d6c3ccadc42b9a87825d94371fb54f490cd6a74b;p=openldap Optimizing UTF8bvnormcmp() by adding flags that tells which arguments are in NFC. By default no arguments are assumed to be NFC. --- diff --git a/include/ldap_pvt_uc.h b/include/ldap_pvt_uc.h index 6778628fa6..b6840fd57f 100644 --- a/include/ldap_pvt_uc.h +++ b/include/ldap_pvt_uc.h @@ -137,8 +137,10 @@ LDAP_LUNICODE_F(void) ucstr2upper( ldap_unicode_t *, ber_len_t ); -#define LDAP_UTF8_CASEFOLD 0x1U #define LDAP_UTF8_NOCASEFOLD 0x0U +#define LDAP_UTF8_CASEFOLD 0x1U +#define LDAP_UTF8_ARG1NFC 0x2U +#define LDAP_UTF8_ARG2NFC 0x4U LDAP_LUNICODE_F(char *) UTF8normalize( struct berval *, diff --git a/libraries/liblunicode/ucstr.c b/libraries/liblunicode/ucstr.c index 31110542d1..988417b804 100644 --- a/libraries/liblunicode/ucstr.c +++ b/libraries/liblunicode/ucstr.c @@ -503,11 +503,14 @@ int UTF8normcmp( int UTF8bvnormcmp( struct berval *bv1, struct berval *bv2, - unsigned casefold ) + unsigned flags ) { int i, l1, l2, len, ulen, res; char *s1, *s2, *done; unsigned long *ucs, *ucsout1, *ucsout2; + unsigned casefold = flags & LDAP_UTF8_CASEFOLD; + unsigned norm1 = flags & LDAP_UTF8_ARG1NFC; + unsigned norm2 = flags & LDAP_UTF8_ARG2NFC; if (bv1 == NULL) { return bv2 == NULL ? 0 : -1; @@ -575,7 +578,7 @@ int UTF8bvnormcmp( * proper normalized form. */ - ucs = (long *) malloc( ( l1 > l2 ? l1 : l2 ) * sizeof(*ucs) ); + ucs = (long *) malloc( ( ( norm1 || l1 > l2 ) ? l1 : l2 ) * sizeof(*ucs) ); if ( ucs == NULL ) { return l1 > l2 ? 1 : -1; /* what to do??? */ } @@ -594,8 +597,18 @@ int UTF8bvnormcmp( } len = LDAP_UTF8_CHARLEN( s1 + i ); } - uccanondecomp( ucs, ulen, &ucsout1, &l1 ); - l1 = uccanoncomp( ucsout1, l1 ); + + if ( norm1 ) { + ucsout1 = ucs; + l1 = ulen; + ucs = (long *) malloc( l2 * sizeof(*ucs) ); + if ( ucs == NULL ) { + return l1 > l2 ? 1 : -1; /* what to do??? */ + } + } else { + uccanondecomp( ucs, ulen, &ucsout1, &l1 ); + l1 = uccanoncomp( ucsout1, l1 ); + } /* convert and normalize 2nd string */ for ( i = 0, ulen = 0; i < l2; i += len, ulen++ ) { @@ -607,11 +620,16 @@ int UTF8bvnormcmp( } len = LDAP_UTF8_CHARLEN( s2 + i ); } - uccanondecomp( ucs, ulen, &ucsout2, &l2 ); - l2 = uccanoncomp( ucsout2, l2 ); - - free( ucs ); + if ( norm2 ) { + ucsout2 = ucs; + l2 = ulen; + } else { + uccanondecomp( ucs, ulen, &ucsout2, &l2 ); + l2 = uccanoncomp( ucsout2, l2 ); + free( ucs ); + } + res = casefold ? ucstrncasecmp( ucsout1, ucsout2, l1 < l2 ? l1 : l2 ) : ucstrncmp( ucsout1, ucsout2, l1 < l2 ? l1 : l2 );