mirror of
https://github.com/status-im/NimYAML.git
synced 2025-01-11 20:14:19 +00:00
Fixed problem with JSON handling.
* use `[]=` instead of add() to add JSON nodes to an object. add() seems to have problems with expanding. * renamed bench/json.nim to bench/jsonBench.nim to avoid confusion with Nim's stdlib json.nim
This commit is contained in:
parent
5933605591
commit
00e10ff9ce
@ -156,6 +156,21 @@ var
|
||||
tagLib = initCoreTagLibrary()
|
||||
parser = newYamlParser(initCoreTagLibrary())
|
||||
|
||||
block:
|
||||
multibench(cJson1k, 100):
|
||||
let res = parseJson(json1k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cJson10k, 100):
|
||||
let res = parseJson(json10k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cJson100k, 100):
|
||||
let res = parseJson(json100k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cYaml1k, 100):
|
||||
var
|
||||
@ -180,21 +195,6 @@ block:
|
||||
let res = constructJson(events)
|
||||
assert res[0].kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cJson1k, 100):
|
||||
let res = parseJson(json1k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cJson10k, 100):
|
||||
let res = parseJson(json10k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cJson100k, 100):
|
||||
let res = parseJson(json100k)
|
||||
assert res.kind == JObject
|
||||
|
||||
block:
|
||||
multibench(cLibYaml1k, 100):
|
||||
let res = nimlets_yaml.load(json1k)
|
||||
@ -221,10 +221,12 @@ writeStyled "1k input\n--------\n"
|
||||
writeResult "NimYAML: ", cYaml1k div 1000
|
||||
writeResult "JSON: ", cJson1k div 1000
|
||||
writeResult "LibYAML: ", cLibYaml1k div 1000
|
||||
setForegroundColor(fgWhite)
|
||||
writeStyled "10k input\n---------\n"
|
||||
writeResult "NimYAML: ", cYaml10k div 1000
|
||||
writeResult "JSON: ", cJson10k div 1000
|
||||
writeResult "LibYAML: ", cLibYaml10k div 1000
|
||||
setForegroundColor(fgWhite)
|
||||
writeStyled "100k input\n----------\n"
|
||||
writeResult "NimYAML: ", cYaml100k div 1000
|
||||
writeResult "JSON: ", cJson100k div 1000
|
@ -28,14 +28,14 @@ task documentation, "Generate documentation":
|
||||
setCommand "nop"
|
||||
|
||||
task bench, "Benchmarking":
|
||||
--d:release
|
||||
#--d:release
|
||||
--r
|
||||
--w:off
|
||||
--hints:off
|
||||
setCommand "c", "bench/json"
|
||||
setCommand "c", "bench/jsonBench"
|
||||
|
||||
task clean, "Remove all generated files":
|
||||
exec "rm -f libyaml.* test/tests test/parsing test/lexing docout"
|
||||
exec "rm -rf libyaml.* test/tests test/parsing test/lexing bench/json docout"
|
||||
setCommand "nop"
|
||||
|
||||
task server, "Compile server daemon":
|
||||
|
@ -125,8 +125,8 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] =
|
||||
else:
|
||||
let jsonScalar = jsonFromScalar(event.scalarContent,
|
||||
event.scalarTag)
|
||||
levels[levels.high].node.fields.add(
|
||||
levels[levels.high].key, jsonScalar)
|
||||
levels[levels.high].node[levels[levels.high].key] =
|
||||
jsonScalar
|
||||
levels[levels.high].key = nil
|
||||
if event.scalarAnchor != yAnchorNone:
|
||||
anchors[event.scalarAnchor] = jsonScalar
|
||||
@ -140,12 +140,11 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] =
|
||||
levels[levels.high].node.elems.add(level.node)
|
||||
of JObject:
|
||||
if isNil(levels[levels.high].key):
|
||||
echo level.node.pretty()
|
||||
raise newException(YamlConstructionError,
|
||||
"non-scalar as key not allowed in JSON")
|
||||
else:
|
||||
levels[levels.high].node.fields.add(
|
||||
levels[levels.high].key, level.node)
|
||||
levels[levels.high].node[
|
||||
levels[levels.high].key] = level.node
|
||||
levels[levels.high].key = nil
|
||||
else:
|
||||
discard # will never happen
|
||||
|
Loading…
x
Reference in New Issue
Block a user