]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Make strtok benchmark competive.
authorOndřej Bílka <neleai@seznam.cz>
Fri, 28 Feb 2014 21:45:33 +0000 (22:45 +0100)
committerOndřej Bílka <neleai@seznam.cz>
Fri, 28 Feb 2014 21:45:33 +0000 (22:45 +0100)
We include a generic version of strtok to result which could be faster
when underlying primitives are better optimized than current version.

benchtests/bench-strtok.c
string/strtok.c

index 5e80c1a77587550ac21a14b442aabdfafdf81469..f2f3f575cde15c2097686fbb64d1fec08a51638e 100644 (file)
 #define TEST_NAME "strtok"
 #include "bench-string.h"
 
-char *
-simple_strtok (char *s1, char *s2)
-{
-  static char *saveptr;
-  char *token;
-  ssize_t i = 0, j = 0;
-  int found = 0;
-  size_t s2len = strlen (s2);
-
-  if (s1 == NULL)
-    s1 = saveptr;
-  if (s1 == NULL || *s1 == '\0')
-    return NULL;
-
-  while (!found)
-    {
-      if (s1[i] == '\0')
-       {
-         saveptr = NULL;
-         return NULL;
-       }
-      for (j = 0; j < s2len; j++)
-       {
-         if (s1[i] == s2[j])
-           {
-             i++;
-             found = 0;
-             break;
-           }
-         found = 1;
-       }
-    }
-  token = s1 + i;
-  i++;
-  found = 0;
-  while (!found)
-    {
-      if (s1[i] == '\0')
-       {
-         saveptr = NULL;
-         return token;
-       }
-      for (j = 0; j < s2len; j++)
-       {
-         if (s1[i] == s2[j])
-           {
-             found = 1;
-             break;
-           }
-       }
-      i++;
-    }
-  s1[i - 1] = '\0';
-  saveptr = s1 + i;
-  return token;
-}
+#define STRTOK strtok_string
+#include <string/strtok.c>
+
 
 typedef char *(*proto_t) (const char *, const char *);
 
-IMPL (simple_strtok, 0)
+IMPL (strtok_string, 0)
 IMPL (strtok, 1)
 
 static void
index f7f709908f8e0b413ce87a711bc06a32ddfaf40b..225344003e29574f47003e88078ab6ee43b93c08 100644 (file)
@@ -22,6 +22,10 @@ static char *olds;
 
 #undef strtok
 
+#ifndef STRTOK
+# define STRTOK strtok
+#endif
+
 /* Parse S into tokens separated by characters in DELIM.
    If S is NULL, the last string strtok() was called with is
    used.  For example:
@@ -32,7 +36,7 @@ static char *olds;
                // s = "abc\0=-def\0"
 */
 char *
-strtok (s, delim)
+STRTOK (s, delim)
      char *s;
      const char *delim;
 {