diff options
author | Daniel Stone <daniel@fooishbar.org> | 2010-06-07 22:43:01 +0100 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2010-06-15 19:26:49 +0100 |
commit | 02de53d767b20bab1517b4e8a3e7eb3b9e7f15be (patch) | |
tree | e917c813c074a6acb89f03cd15dcc36855c8388c | |
parent | 07cc4d60dea2b4c947fed45b082edae4a53b186a (diff) |
Lazy keysym parsing (avoid XStringToKeysym)
Instead of calling XStringToKeysym on every keysym we parse, store it as
a string until we need to store it in an actual keymap.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r-- | parseutils.c | 10 | ||||
-rw-r--r-- | parseutils.h | 4 | ||||
-rw-r--r-- | symbols.c | 9 | ||||
-rw-r--r-- | xkbcomp.h | 2 | ||||
-rw-r--r-- | xkbparse.y | 37 |
5 files changed, 25 insertions, 37 deletions
diff --git a/parseutils.c b/parseutils.c index ad1b0d1..d59e3fb 100644 --- a/parseutils.c +++ b/parseutils.c @@ -392,7 +392,7 @@ ActionCreate(Atom name, ExprDef * args) } ExprDef * -CreateKeysymList(KeySym sym) +CreateKeysymList(char *sym) { ExprDef *def; @@ -400,8 +400,8 @@ CreateKeysymList(KeySym sym) if (def) { def->value.list.nSyms = 1; - def->value.list.szSyms = 2; - def->value.list.syms = uTypedCalloc(2, KeySym); + def->value.list.szSyms = 4; + def->value.list.syms = uTypedCalloc(4, char *); if (def->value.list.syms != NULL) { def->value.list.syms[0] = sym; @@ -600,7 +600,7 @@ DoodadCreate(unsigned type, Atom name, VarDef * body) } ExprDef * -AppendKeysymList(ExprDef * list, KeySym sym) +AppendKeysymList(ExprDef * list, char *sym) { if (list->value.list.nSyms >= list->value.list.szSyms) { @@ -608,7 +608,7 @@ AppendKeysymList(ExprDef * list, KeySym sym) list->value.list.syms = uTypedRecalloc(list->value.list.syms, list->value.list.nSyms, list->value.list.szSyms, - KeySym); + char *); if (list->value.list.syms == NULL) { FATAL("Couldn't resize list of symbols for append\n"); diff --git a/parseutils.h b/parseutils.h index 73a0ec8..e16adff 100644 --- a/parseutils.h +++ b/parseutils.h @@ -121,7 +121,7 @@ extern ExprDef *ActionCreate(Atom /* name */ , ExprDef * /* args */ ); -extern ExprDef *CreateKeysymList(KeySym /* sym */ +extern ExprDef *CreateKeysymList(char * /* sym */ ); extern ShapeDef *ShapeDeclCreate(Atom /* name */ , @@ -161,7 +161,7 @@ extern DoodadDef *DoodadCreate(unsigned /* type */ , ); extern ExprDef *AppendKeysymList(ExprDef * /* list */ , - KeySym /* sym */ + char * /* sym */ ); extern int LookupKeysym(char * /* str */ , @@ -27,6 +27,7 @@ #include "xkbcomp.h" #include "tokens.h" #include "expr.h" +#include "parseutils.h" #include <X11/keysym.h> #include <X11/Xutil.h> @@ -968,8 +969,12 @@ AddSymbolsToKey(KeyInfo * key, return False; } key->symsDefined |= (1 << ndx); - memcpy((char *) key->syms[ndx], (char *) value->value.list.syms, - nSyms * sizeof(KeySym)); + for (i = 0; i < nSyms; i++) { + if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) { + WSGO1("Could not resolve keysym %s\n", value->value.list.syms[i]); + key->syms[ndx][i] = NoSymbol; + } + } for (i = key->numLevels[ndx] - 1; (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--) { @@ -156,7 +156,7 @@ typedef struct _Expr { int nSyms; int szSyms; - KeySym *syms; + char **syms; } list; struct { @@ -136,9 +136,9 @@ unsigned int parseDebug; XkbFile *file; } %type <ival> Number Integer Float SignedNumber -%type <uval> XkbCompositeType FileType MergeMode OptMergeMode KeySym +%type <uval> XkbCompositeType FileType MergeMode OptMergeMode %type <uval> DoodadType Flag Flags OptFlags -%type <str> KeyName MapName OptMapName +%type <str> KeyName MapName OptMapName KeySym %type <sval> FieldSpec Ident Element String %type <any> DeclList Decl %type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit @@ -374,9 +374,9 @@ InterpretDecl : INTERPRET InterpretMatch OBRACE ; InterpretMatch : KeySym PLUS Expr - { $$= InterpCreate((KeySym)$1,$3); } + { $$= InterpCreate(XStringToKeysym($1), $3); } | KeySym - { $$= InterpCreate((KeySym)$1,NULL); } + { $$= InterpCreate(XStringToKeysym($1), NULL); } ; VarDeclList : VarDeclList VarDecl @@ -716,34 +716,17 @@ OptKeySymList : KeySymList { $$= $1; } ; KeySymList : KeySymList COMMA KeySym - { $$= AppendKeysymList($1,(KeySym)$3); } + { $$= AppendKeysymList($1,$3); } | KeySym - { $$= CreateKeysymList((KeySym)$1); } + { $$= CreateKeysymList($1); } ; -KeySym : IDENT - { - KeySym sym; - if (LookupKeysym(scanStr,&sym)) - $$= sym; - else { - char buf[120]; - snprintf(buf, sizeof(buf), - "expected keysym, got %s", - uStringText(scanStr)); - yyerror(buf); - yynerrs++; - $$= NoSymbol; - } - } - | SECTION - { - $$= XK_section; - } +KeySym : IDENT { $$= scanStr; scanStr= NULL; } + | SECTION { $$= strdup("section"); } | Integer { - if ($1<10) $$= $1+'0'; /* XK_0 .. XK_9 */ - else $$= $1; + if ($1<10) { $$= malloc(2); $$[0]= '0' + $1; $$[1]= '\0'; } + else { $$= malloc(17); snprintf($$, 17, "%x", $1); } } ; |