From: Pádraig Brady
Date: Fri, 21 Jan 2011 12:40:28 +0000 (+0100) Subject: Prepare for faster uN_strstr functions. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b1e945287b0e30a238102974f7a51f24def2a79;p=pspp Prepare for faster uN_strstr functions. * lib/str-kmp.h: Support definable UNITs. (knuth_morris_pratt): Renamed from knuth_morris_pratt_unibyte. Add needle_len argument. * lib/mbsstr.c (mbsstr): Adjust for the changed str-kmp.h. * lib/mbscasestr.c (mbscasestr): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 9bb96b85b0..468e317f53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-01-21 Pádraig Brady
+ Bruno Haible
malloca-tests: make faster by unsetting MALLOC_PERTURB_
diff --git a/lib/mbscasestr.c b/lib/mbscasestr.c
index 379b2fb033..f013808d5b 100644
--- a/lib/mbscasestr.c
+++ b/lib/mbscasestr.c
@@ -30,6 +30,7 @@
#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
/* Knuth-Morris-Pratt algorithm. */
+#define UNIT unsigned char
#define CANON_ELEMENT(c) TOLOWER (c)
#include "str-kmp.h"
@@ -368,10 +369,12 @@ mbscasestr (const char *haystack, const char *needle)
if (needle_last_ccount == NULL)
{
/* Try the Knuth-Morris-Pratt algorithm. */
- const char *result;
+ const unsigned char *result;
bool success =
- knuth_morris_pratt_unibyte (haystack, needle - 1,
- &result);
+ knuth_morris_pratt ((const unsigned char *) haystack,
+ (const unsigned char *) (needle - 1),
+ strlen (needle - 1),
+ &result);
if (success)
return (char *) result;
try_kmp = false;
diff --git a/lib/mbsstr.c b/lib/mbsstr.c
index 513dde1ab4..611000e6dd 100644
--- a/lib/mbsstr.c
+++ b/lib/mbsstr.c
@@ -27,6 +27,7 @@
#include "mbuiter.h"
/* Knuth-Morris-Pratt algorithm. */
+#define UNIT unsigned char
#define CANON_ELEMENT(c) c
#include "str-kmp.h"
@@ -339,10 +340,12 @@ mbsstr (const char *haystack, const char *needle)
if (needle_last_ccount == NULL)
{
/* Try the Knuth-Morris-Pratt algorithm. */
- const char *result;
+ const unsigned char *result;
bool success =
- knuth_morris_pratt_unibyte (haystack, needle - 1,
- &result);
+ knuth_morris_pratt ((const unsigned char *) haystack,
+ (const unsigned char *) (needle - 1),
+ strlen (needle - 1),
+ &result);
if (success)
return (char *) result;
try_kmp = false;
diff --git a/lib/str-kmp.h b/lib/str-kmp.h
index 95a73f571c..d7e0a74541 100644
--- a/lib/str-kmp.h
+++ b/lib/str-kmp.h
@@ -1,4 +1,4 @@
-/* Substring search in a NUL terminated string of 'char' elements,
+/* Substring search in a NUL terminated string of UNIT elements,
using the Knuth-Morris-Pratt algorithm.
Copyright (C) 2005-2011 Free Software Foundation, Inc.
Written by Bruno Haible