summaryrefslogtreecommitdiff
path: root/ext/tokenizer/tokenizer.c
diff options
context:
space:
mode:
authorTyson Andre <tysonandre775@hotmail.com>2019-09-28 09:54:43 -0400
committerNikita Popov <nikita.ppv@gmail.com>2019-09-28 21:29:58 +0200
commit7e0f7b7677e2fd76e83c2b731c3c0f3bd1a7279e (patch)
treebe036bcda2906c5975660c098273818bca332c5f /ext/tokenizer/tokenizer.c
parent1b08ab26f7729629b6c14750114a0be455c9f4f7 (diff)
downloadphp-git-7e0f7b7677e2fd76e83c2b731c3c0f3bd1a7279e.tar.gz
Reduce memory used by token_get_all()
Around a quarter of all strings in array tokens would have a string that's one character long (e.g. ` `, `\`, `1`) For parsing a large number of php files, The memory increase dropped from 378374248 to 369535688 (2.5%) Closes GH-4753.
Diffstat (limited to 'ext/tokenizer/tokenizer.c')
-rw-r--r--ext/tokenizer/tokenizer.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c
index 91ace6f701..3d343fec4d 100644
--- a/ext/tokenizer/tokenizer.c
+++ b/ext/tokenizer/tokenizer.c
@@ -110,7 +110,11 @@ static void add_token(zval *return_value, int token_type,
zval keyword;
array_init(&keyword);
add_next_index_long(&keyword, token_type);
- add_next_index_stringl(&keyword, (char *) text, leng);
+ if (leng == 1) {
+ add_next_index_str(&keyword, ZSTR_CHAR(text[0]));
+ } else {
+ add_next_index_stringl(&keyword, (char *) text, leng);
+ }
add_next_index_long(&keyword, lineno);
add_next_index_zval(return_value, &keyword);
} else {