diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-24 01:18:11 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-24 01:18:11 -0500 |
commit | b7f56459d566e232a554ab29bcf1015b303d59b1 (patch) | |
tree | 145ac4024c558fbbb58d3053f7cbe8f09b79bca4 /dimension | |
parent | e5f268e84dbe121d063de8ec73ad53c36b9e8d83 (diff) | |
download | dimension-b7f56459d566e232a554ab29bcf1015b303d59b1.tar.xz |
Make string lexing O(n).
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/flex.l | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/dimension/flex.l b/dimension/flex.l index 8c3008d..2e2467c 100644 --- a/dimension/flex.l +++ b/dimension/flex.l @@ -71,22 +71,27 @@ #define STRING_TOKEN() \ do { \ NEW_TOKEN(DMNSN_T_STRING); \ - token.value = malloc(1); \ - token.value[0] = '\0'; \ string_length = 0; \ + string_extent = 8; \ + token.value = malloc(string_extent); \ + token.value[0] = '\0'; \ CALCULATE_COLUMN(); \ } while (0) #define STRCAT(str, len) \ do { \ - token.value = realloc(token.value, string_length + len + 1); \ + if (string_length + len + 1 >= string_length) { \ + string_extent = 2*(string_length + len + 1); \ + token.value = realloc(token.value, string_extent); \ + } \ + \ strncpy(token.value + string_length, str, len + 1); \ string_length += len; \ CALCULATE_COLUMN(); \ } while(0) dmnsn_token token; -size_t string_length; +size_t string_length, string_extent; unsigned long wchar; %} |