mirror of https://github.com/status-im/NimYAML.git
Some performance optimization with shallowCopy
This commit is contained in:
parent
d3053f381f
commit
93ce0b26ba
|
@ -60,7 +60,7 @@ proc composeNode(s: var YamlStream, tagLib: TagLibrary,
|
|||
of yamlScalar:
|
||||
result.tag = tagLib.uri(start.scalarTag)
|
||||
result.kind = yScalar
|
||||
result.content = start.scalarContent
|
||||
shallowCopy(result.content, start.scalarContent)
|
||||
if start.scalarAnchor != yAnchorNone:
|
||||
assert(not c.refs.hasKey(start.scalarAnchor))
|
||||
c.refs[start.scalarAnchor] = cast[pointer](result)
|
||||
|
|
|
@ -61,7 +61,7 @@ proc jsonFromScalar(content: string, tag: TagId): JsonNode
|
|||
result.kind = JNull
|
||||
else:
|
||||
result.kind = JString
|
||||
result.str = content
|
||||
shallowCopy(result.str, content)
|
||||
except ValueError:
|
||||
var e = newException(YamlConstructionError,
|
||||
"Cannot parse numeric value")
|
||||
|
|
|
@ -11,7 +11,13 @@ proc initYamlStream*(backend: iterator(): YamlStreamEvent): YamlStream =
|
|||
proc next*(s: var YamlStream): YamlStreamEvent =
|
||||
if s.peeked:
|
||||
s.peeked = false
|
||||
result = s.cached
|
||||
if s.cached.kind == yamlScalar:
|
||||
# performance optimization
|
||||
result = YamlStreamEvent(kind: yamlScalar,
|
||||
scalarTag: s.cached.scalarTag,
|
||||
scalarAnchor: s.cached.scalarAnchor)
|
||||
shallowCopy(result.scalarContent, s.cached.scalarContent)
|
||||
else: result = s.cached
|
||||
else:
|
||||
try:
|
||||
result = s.backend()
|
||||
|
|
Loading…
Reference in New Issue