[memcached] sgrimm,
r514: Apply command tokenizer performance/clea...
commits at code.sixapart.com
commits at code.sixapart.com
Tue Apr 17 00:44:49 UTC 2007
Apply command tokenizer performance/cleanup patch from Paolo Borelli.
U trunk/server/ChangeLog
U trunk/server/memcached.c
Modified: trunk/server/ChangeLog
===================================================================
--- trunk/server/ChangeLog 2007-04-17 00:24:53 UTC (rev 513)
+++ trunk/server/ChangeLog 2007-04-17 00:44:49 UTC (rev 514)
@@ -1,11 +1,14 @@
+2007-04-16 Steven Grimm <sgrimm at facebook.com>
+ * Command tokenizer performance and cleanliness improvement.
+ Patch contributed by Paolo Borelli <paolo.borelli at gmail.com>.
+
2007-04-16 Paul Lindner <lindner at inuus.com>
* Add notes to README about MacOS, libevent and kqueue.
* Windows Patch integration -- part 1, warnings elimination.
-
2007-04-12 Paul Lindner <lindner at mirth.inuus.com>
* Allow changes to the verbosity level of the server with a new
Modified: trunk/server/memcached.c
===================================================================
--- trunk/server/memcached.c 2007-04-17 00:24:53 UTC (rev 513)
+++ trunk/server/memcached.c 2007-04-17 00:44:49 UTC (rev 514)
@@ -775,46 +775,38 @@
* 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;
+ s = e + 1;
+ }
+ else if (*e == '\0') {
+ if (s != e) {
+ tokens[ntokens].value = s;
+ tokens[ntokens].length = e - s;
+ ntokens++;
}
- length++;
+
+ break; /* string end */
}
- cp++;
}
- if(ntokens < max_tokens - 1 && length > 0) {
- tokens[ntokens].value = value;
- tokens[ntokens].length = length;
- ntokens++;
- }
-
/*
* 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++;
More information about the memcached-commits
mailing list