diff options
author | Paolo Borelli <pborelli@katamail.com> | 2007-04-17 00:44:49 +0000 |
---|---|---|
committer | Paolo Borelli <pborelli@katamail.com> | 2007-04-17 00:44:49 +0000 |
commit | ce96a20854ff56f40627acd875dff67fab7bcfb2 (patch) | |
tree | 6f8c79e10c327d9f3746fdcacbf83cdac2cc5ead | |
parent | fb6b20babe220f96764e6edd58d3369c94a1bf38 (diff) | |
download | memcached-ce96a20854ff56f40627acd875dff67fab7bcfb2.tar.gz |
Apply command tokenizer performance/cleanup patch from Paolo Borelli.
git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@514 b0b603af-a30f-0410-a34e-baf09ae79d0b
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | memcached.c | 44 |
2 files changed, 22 insertions, 27 deletions
@@ -1,3 +1,7 @@ +2007-04-16 Steven Grimm <sgrimm@facebook.com> + + * Command tokenizer performance and cleanliness improvement. + Patch contributed by Paolo Borelli <paolo.borelli@gmail.com>. 2007-04-16 Paul Lindner <lindner@inuus.com> @@ -5,7 +9,6 @@ * Windows Patch integration -- part 1, warnings elimination. - 2007-04-12 Paul Lindner <lindner@mirth.inuus.com> * Allow changes to the verbosity level of the server with a new diff --git a/memcached.c b/memcached.c index f5db6af..6b8a020 100644 --- a/memcached.c +++ b/memcached.c @@ -775,46 +775,38 @@ typedef struct token_s { * command = tokens[ix].value; * } */ -static size_t tokenize_command(char *command, token_t *tokens, const size_t max_tokens) { - char *cp; - char *value = NULL; - size_t length = 0; +static size_t tokenize_command(char *command, token_t *tokens, const size_t max_tokens) { + char *s, *e; size_t ntokens = 0; assert(command != NULL && tokens != NULL && max_tokens > 1); - cp = command; - while(*cp != '\0' && ntokens < max_tokens - 1) { - if(*cp == ' ') { - // If we've accumulated a token, this is the end of it. - if(length > 0) { - tokens[ntokens].value = value; - tokens[ntokens].length = length; + for (s = e = command; ntokens < max_tokens - 1; ++e) { + if (*e == ' ') { + if (s != e) { + tokens[ntokens].value = s; + tokens[ntokens].length = e - s; ntokens++; - length = 0; - value = NULL; + *e = '\0'; } - *cp = '\0'; - } else { - if(length == 0) { - value = cp; - } - length++; + s = e + 1; } - cp++; - } + else if (*e == '\0') { + if (s != e) { + tokens[ntokens].value = s; + tokens[ntokens].length = e - s; + ntokens++; + } - if(ntokens < max_tokens - 1 && length > 0) { - tokens[ntokens].value = value; - tokens[ntokens].length = length; - ntokens++; + break; /* string end */ + } } /* * If we scanned the whole string, the terminal value pointer is null, * otherwise it is the first unprocessed character. */ - tokens[ntokens].value = *cp == '\0' ? NULL : cp; + tokens[ntokens].value = *e == '\0' ? NULL : e; tokens[ntokens].length = 0; ntokens++; |