scanner: avoid strlen in keyword lookup, we know the len Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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);