]> git.sur5r.net Git - openldap/commitdiff
Optimizing UTF8bvnormcmp() by adding flags that tells which arguments are
authorStig Venaas <venaas@openldap.org>
Mon, 25 Feb 2002 13:20:09 +0000 (13:20 +0000)
committerStig Venaas <venaas@openldap.org>
Mon, 25 Feb 2002 13:20:09 +0000 (13:20 +0000)
in NFC. By default no arguments are assumed to be NFC.

include/ldap_pvt_uc.h
libraries/liblunicode/ucstr.c

index 6778628fa6c3a8c680ebbf9e57a46a5c8c33c7a7..b6840fd57f20009916c88c168eca1b66d9d6da90 100644 (file)
@@ -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 *,
index 31110542d14f3149ebf769215c9923a692252f65..988417b8043fe4174b3ba228a68404f1cd03638b 100644 (file)
@@ -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 );