diff options
author | Shea Levy <shea@shealevy.com> | 2018-02-19T15·11-0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2018-02-19T15·11-0500 |
commit | e1eb63a5860dd7efaf66c3ec83006c58f87bf3cb (patch) | |
tree | 1c7fee9a7adecc4641db4b9238ed38cea66ebb4a /src/libexpr/lexer.l | |
parent | ed73d40c3b19dc0581bbf28ef29aad50cab3aaf2 (diff) | |
parent | 37264ed0ad898cdd6880de8ce6e5dda7977eed5f (diff) |
Merge branch 'perf-fixes' of git://github.com/dezgeg/nix
Diffstat (limited to 'src/libexpr/lexer.l')
-rw-r--r-- | src/libexpr/lexer.l | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 28a0a6a87896..e5e01fb5831a 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -49,9 +49,10 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len) } -static Expr * unescapeStr(SymbolTable & symbols, const char * s) +static Expr * unescapeStr(SymbolTable & symbols, const char * s, size_t length) { string t; + t.reserve(length); char c; while ((c = *s++)) { if (c == '\\') { @@ -150,7 +151,7 @@ or { return OR_KW; } /* It is impossible to match strings ending with '$' with one regex because trailing contexts are only valid at the end of a rule. (A sane but undocumented limitation.) */ - yylval->e = unescapeStr(data->symbols, yytext); + yylval->e = unescapeStr(data->symbols, yytext, yyleng); return STR; } <STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; } @@ -178,7 +179,7 @@ or { return OR_KW; } return IND_STR; } <IND_STRING>\'\'\\. { - yylval->e = unescapeStr(data->symbols, yytext + 2); + yylval->e = unescapeStr(data->symbols, yytext + 2, yyleng - 2); return IND_STR; } <IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; } |