Some performance optimization with shallowCopy

This commit is contained in:
Felix Krause 2016-03-25 10:13:55 +01:00
parent d3053f381f
commit 93ce0b26ba
3 changed files with 9 additions and 3 deletions

View File

@ -60,7 +60,7 @@ proc composeNode(s: var YamlStream, tagLib: TagLibrary,
of yamlScalar: of yamlScalar:
result.tag = tagLib.uri(start.scalarTag) result.tag = tagLib.uri(start.scalarTag)
result.kind = yScalar result.kind = yScalar
result.content = start.scalarContent shallowCopy(result.content, start.scalarContent)
if start.scalarAnchor != yAnchorNone: if start.scalarAnchor != yAnchorNone:
assert(not c.refs.hasKey(start.scalarAnchor)) assert(not c.refs.hasKey(start.scalarAnchor))
c.refs[start.scalarAnchor] = cast[pointer](result) c.refs[start.scalarAnchor] = cast[pointer](result)

View File

@ -61,7 +61,7 @@ proc jsonFromScalar(content: string, tag: TagId): JsonNode
result.kind = JNull result.kind = JNull
else: else:
result.kind = JString result.kind = JString
result.str = content shallowCopy(result.str, content)
except ValueError: except ValueError:
var e = newException(YamlConstructionError, var e = newException(YamlConstructionError,
"Cannot parse numeric value") "Cannot parse numeric value")

View File

@ -11,7 +11,13 @@ proc initYamlStream*(backend: iterator(): YamlStreamEvent): YamlStream =
proc next*(s: var YamlStream): YamlStreamEvent = proc next*(s: var YamlStream): YamlStreamEvent =
if s.peeked: if s.peeked:
s.peeked = false 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: else:
try: try:
result = s.backend() result = s.backend()