From bba44965bf13f02acc79d747cbd4dd004fe42614 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sat, 7 Jan 2006 21:00:51 +0100 Subject: [PATCH] check_uri_file(): optimize by not using strlen() more than needed. --- src/protocol/uri.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/protocol/uri.c b/src/protocol/uri.c index ad10ec8d7..7538ca92e 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -151,21 +151,17 @@ check_uri_file(unsigned char *name) /* Check POST_CHAR etc ... */ static const unsigned char chars[] = POST_CHAR_S "#?"; int i; + int namelen = strlen(name); for (i = 0; i < sizeof(chars) - 1; i++) { - unsigned char *pos = strchr(name, chars[i]); - int namelen; - + unsigned char *pos = memchr(name, chars[i], namelen); + if (!pos) continue; - *pos = 0; - namelen = strlen(name); - *pos = chars[i]; - - return namelen; + return pos - name; } - return strlen(name); + return namelen; } /* Encodes URIs without encoding stuff like fragments and query separators. */