From: Ran Benita Date: Fri, 7 Feb 2014 16:09:30 +0000 (+0200) Subject: scanner: avoid strlen in keyword lookup, we know the len X-Git-Tag: xkbcommon-0.4.1~86 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b82a0a86504cd5ec279ffa3a967be4b22e3a7474;p=platform%2Fupstream%2Flibxkbcommon.git scanner: avoid strlen in keyword lookup, we know the len Signed-off-by: Ran Benita --- diff --git a/src/xkbcomp/keywords.c b/src/xkbcomp/keywords.c index c19d66f..abab7fe 100644 --- a/src/xkbcomp/keywords.c +++ b/src/xkbcomp/keywords.c @@ -339,10 +339,9 @@ keyword_gperf_lookup (register const char *str, register unsigned int len) int -keyword_to_token(const char *string) +keyword_to_token(const char *string, unsigned int len) { - const struct keyword_tok *kt; - kt = keyword_gperf_lookup(string, strlen(string)); + const struct keyword_tok *kt = keyword_gperf_lookup(string, len); if (!kt) return -1; return kt->tok; diff --git a/src/xkbcomp/keywords.gperf b/src/xkbcomp/keywords.gperf index 4a77703..5c64144 100644 --- a/src/xkbcomp/keywords.gperf +++ b/src/xkbcomp/keywords.gperf @@ -69,10 +69,9 @@ xkb_types, XKB_TYPES %% int -keyword_to_token(const char *string) +keyword_to_token(const char *string, unsigned int len) { - const struct keyword_tok *kt; - kt = keyword_gperf_lookup(string, strlen(string)); + const struct keyword_tok *kt = keyword_gperf_lookup(string, len); if (!kt) return -1; return kt->tok; diff --git a/src/xkbcomp/parser-priv.h b/src/xkbcomp/parser-priv.h index 05e725e..08475a7 100644 --- a/src/xkbcomp/parser-priv.h +++ b/src/xkbcomp/parser-priv.h @@ -45,6 +45,6 @@ XkbFile * parse(struct xkb_context *ctx, void *scanner, const char *map); int -keyword_to_token(const char *string); +keyword_to_token(const char *string, unsigned int len); #endif diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c index 48df488..45a5940 100644 --- a/src/xkbcomp/scanner.c +++ b/src/xkbcomp/scanner.c @@ -169,7 +169,7 @@ skip_more_whitespace_and_comments: return scanner_error(s, "identifier too long"); /* Keyword. */ - tok = keyword_to_token(s->buf); + tok = keyword_to_token(s->buf, s->buf_pos - 1); if (tok != -1) return tok; yylval->str = strdup(s->buf);