diff options
author | Daniel Stone <daniel@fooishbar.org> | 2010-06-08 15:11:19 +0100 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2010-06-15 19:26:49 +0100 |
commit | 41b0857c8c1179b87a26888588cbfff28f8bb0d6 (patch) | |
tree | 19a906b75cfddd57c333920759e7bba4d98a4ee9 /xkbscan.c | |
parent | 7f7a57c75beb5e1dfb53351e490ef00a324b2727 (diff) |
Don't malloc() and free() most scanned symbols
Use a constant buffer. Sigh.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'xkbscan.c')
-rw-r--r-- | xkbscan.c | 44 |
1 files changed, 16 insertions, 28 deletions
@@ -45,11 +45,10 @@ int lineNum = 0; int scanInt; -char *scanStr = NULL; +char scanBuf[1024]; static int scanStrLine = 0; #define BUFSIZE 4096 -static int nInBuf = 0; static char readBuf[BUFSIZE]; static int readBufPos = 0; static int readBufLen = 0; @@ -220,7 +219,7 @@ tokText(int tok) break; case STRING: - snprintf(buf, sizeof(buf), "STRING (%s)", scanStr); + snprintf(buf, sizeof(buf), "STRING (%s)", scanBuf); break; case INTEGER: snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt); @@ -230,10 +229,10 @@ tokText(int tok) scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM); break; case IDENT: - snprintf(buf, sizeof(buf), "IDENT (%s)", scanStr); + snprintf(buf, sizeof(buf), "IDENT (%s)", scanBuf); break; case KEYNAME: - snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr); + snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanBuf); break; case PARTIAL: @@ -310,7 +309,6 @@ static int yyGetString(void) { int ch, i; - char buf[1024]; i = 0; while (((ch = scanchar()) != EOF) && (ch != '"')) @@ -378,15 +376,12 @@ yyGetString(void) else return ERROR_TOK; } - if (i < sizeof(buf) - 1) - buf[i++] = ch; + if (i < sizeof(scanBuf) - 1) + scanBuf[i++] = ch; } if (ch == '"') { - buf[i++] = '\0'; - if (scanStr) - uFree(scanStr); - scanStr = (char *) uStringDup(buf); + scanBuf[i++] = '\0'; scanStrLine = lineNum; return STRING; } @@ -397,7 +392,6 @@ static int yyGetKeyName(void) { int ch, i; - char buf[1024]; i = 0; while (((ch = scanchar()) != EOF) && (ch != '>')) @@ -460,15 +454,12 @@ yyGetKeyName(void) return ERROR_TOK; } - if (i < sizeof(buf) - 1) - buf[i++] = ch; + if (i < sizeof(scanBuf) - 1) + scanBuf[i++] = ch; } if ((ch == '>') && (i < 5)) { - buf[i++] = '\0'; - if (scanStr) - uFree(scanStr); - scanStr = (char *) uStringDup(buf); + scanBuf[i++] = '\0'; scanStrLine = lineNum; return KEYNAME; } @@ -579,21 +570,20 @@ yyGetIdent(int first) { int ch, i, j, found; int rtrn = IDENT; - char buf[1024]; - buf[0] = first; + scanBuf[0] = first; j = 1; while (((ch = scanchar()) != EOF) && (isalnum(ch) || (ch == '_'))) { - if (j < sizeof(buf) - 1) - buf[j++] = ch; + if (j < sizeof(scanBuf) - 1) + scanBuf[j++] = ch; } - buf[j++] = '\0'; + scanBuf[j++] = '\0'; found = 0; for (i = 0; (!found) && (i < numKeywords); i++) { - if (uStrCaseCmp(buf, keywords[i].keyword) == 0) + if (uStrCaseCmp(scanBuf, keywords[i].keyword) == 0) { rtrn = keywords[i].token; found = 1; @@ -601,9 +591,6 @@ yyGetIdent(int first) } if (!found) { - if (scanStr) - uFree(scanStr); - scanStr = (char *) uStringDup(buf); scanStrLine = lineNum; rtrn = IDENT; } @@ -621,6 +608,7 @@ yyGetNumber(int ch) { int isFloat = 0; char buf[1024]; + int nInBuf = 0; buf[0] = ch; nInBuf = 1; |