summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-24 01:18:11 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-24 01:18:11 -0500
commitb7f56459d566e232a554ab29bcf1015b303d59b1 (patch)
tree145ac4024c558fbbb58d3053f7cbe8f09b79bca4
parente5f268e84dbe121d063de8ec73ad53c36b9e8d83 (diff)
downloaddimension-b7f56459d566e232a554ab29bcf1015b303d59b1.tar.xz
Make string lexing O(n).
-rw-r--r--dimension/flex.l13
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;
%}