Software /
code /
prosody
Changeset
5561:52eef11cd8af
util.json: Optimize long string parsing.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 05 May 2013 15:02:33 -0400 |
parents | 5553:7baf59444b31 |
children | 5562:a6b8fb827e2a |
files | util/json.lua |
diffstat | 1 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/util/json.lua Wed May 01 13:45:05 2013 +0100 +++ b/util/json.lua Sun May 05 15:02:33 2013 -0400 @@ -258,16 +258,16 @@ return val; end local function readstring() - local s = ""; + local s = {}; checkandskip("\""); while ch do while ch and ch ~= "\\" and ch ~= "\"" do - s = s..ch; next(); + t_insert(s, ch); next(); end if ch == "\\" then next(); if unescapes[ch] then - s = s..unescapes[ch]; + t_insert(s, unescapes[ch]); next(); elseif ch == "u" then local seq = ""; @@ -277,13 +277,13 @@ if not ch:match("[0-9a-fA-F]") then error("invalid unicode escape sequence in string"); end seq = seq..ch; end - s = s..codepoint_to_utf8(tonumber(seq, 16)); + t_insert(s, codepoint_to_utf8(tonumber(seq, 16))); next(); else error("invalid escape sequence in string"); end end if ch == "\"" then next(); - return s; + return t_concat(s); end end error("eof while reading string");