projects
/
prosody.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b11cb25
)
util.json: Optimize long string parsing.
author
Waqas Hussain
<waqas20@gmail.com>
Sun, 5 May 2013 19:02:33 +0000
(15:02 -0400)
committer
Waqas Hussain
<waqas20@gmail.com>
Sun, 5 May 2013 19:02:33 +0000
(15:02 -0400)
util/json.lua
patch
|
blob
|
history
diff --git
a/util/json.lua
b/util/json.lua
index 9c2dd2c6127b6d9275ffba29639eab079ca82d52..6251af1a0ac5b05501e9e222aa4d468587e9d286 100644
(file)
--- a/
util/json.lua
+++ b/
util/json.lua
@@
-258,16
+258,16
@@
function json.decode(json)
return val;
end
local function readstring()
return val;
end
local function readstring()
- local s =
""
;
+ local s =
{}
;
checkandskip("\"");
while ch do
while ch and ch ~= "\\" and ch ~= "\"" do
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
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 = "";
next();
elseif ch == "u" then
local seq = "";
@@
-277,13
+277,13
@@
function json.decode(json)
if not ch:match("[0-9a-fA-F]") then error("invalid unicode escape sequence in string"); end
seq = seq..ch;
end
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();
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");
end
end
error("eof while reading string");