From f73283cf6a5da7586abd0440a65ec6f03a5476c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 16 Oct 2008 15:31:58 +0000 Subject: [PATCH] When opening mails with slightly larger attachements in Beam, I noticed that it was quite sluggish. When opening larger mails, like a 1.14 MB mail for example, it could take almost half a minute until it was displayed. It turned out that the offending thread was in strstr(). This is an implementation taken from Wikipedia (declared as public domain there), which makes the mails open instantly. This usecase may have represented a worst-case scenario for the previous implementation. It may be beneficial to take a look at more of these string functions, but I am happy for now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28172 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/string/strstr.c | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/system/libroot/posix/string/strstr.c b/src/system/libroot/posix/string/strstr.c index 44871f461d..3f8c9e532f 100644 --- a/src/system/libroot/posix/string/strstr.c +++ b/src/system/libroot/posix/string/strstr.c @@ -1,26 +1,23 @@ /* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ + * Taken from Wikipedia, which declared it as "public domain". + */ #include #include char * -strstr(char const *s1, char const *s2) +strstr(const char *s1, const char *s2) { - int l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *)s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1,s2,l2)) - return (char *)s1; - s1++; - } - return NULL; + size_t s2len; + /* Check for the null s2 case. */ + if (*s2 == '\0') + return (char *) s1; + s2len = strlen(s2); + for (; (s1 = strchr(s1, *s2)) != NULL; s1++) { + if (strncmp(s1, s2, s2len) == 0) + return (char *)s1; + } + return NULL; } +