From 2f14d0e10890ccbdf4e2cdb2d553ad38ecb0322d Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 15 Jan 2013 01:09:15 +0100 Subject: fixes a performance regression for json handling --- lib/pure/json.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pure/json.nim b/lib/pure/json.nim index cee135f08..cca1e4a70 100755 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -541,6 +541,11 @@ proc newJString*(s: String): PJsonNode = result.kind = JString result.str = s +proc newJStringMove(s: String): PJsonNode = + new(result) + result.kind = JString + shallowCopy(result.str, s) + proc newJInt*(n: biggestInt): PJsonNode = ## Creates a new `JInt PJsonNode`. new(result) @@ -809,7 +814,9 @@ proc parseJson(p: var TJsonParser): PJsonNode = ## Parses JSON from a JSON Parser `p`. case p.tok of tkString: - result = newJString(p.a) + # we capture 'p.a' here, so we need to give it a fresh buffer afterwards: + result = newJStringMove(p.a) + p.a = "" discard getTok(p) of tkInt: result = newJInt(parseBiggestInt(p.a)) -- cgit 1.4.1-2-gfad0