r2578: Pick up optimisation from Samba4 - thanks tridge !
[samba.git] / source / lib / util_str.c
index 65a616ad4198851b8168b6b5f8840747e3e4130a..2c0cae1d73dbfebf582f9237e7d01c75346e5975 100644 (file)
@@ -1208,6 +1208,12 @@ char *strchr_m(const char *src, char c)
        smb_ucs2_t *p;
        const char *s;
 
+       /* characters below 0x3F are guaranteed to not appear in
+          non-initial position in multi-byte charsets */
+       if ((c & 0xC0) == 0) {
+               return strchr(s, c);
+       }
+
        /* this is quite a common operation, so we want it to be
           fast. We optimise for the ascii case, knowing that all our
           supported multi-byte character sets are ascii-compatible
@@ -1237,6 +1243,12 @@ char *strchr_m(const char *src, char c)
 
 char *strrchr_m(const char *s, char c)
 {
+       /* characters below 0x3F are guaranteed to not appear in
+          non-initial position in multi-byte charsets */
+       if ((c & 0xC0) == 0) {
+               return strrchr(s, c);
+       }
+
        /* this is quite a common operation, so we want it to be
           fast. We optimise for the ascii case, knowing that all our
           supported multi-byte character sets are ascii-compatible