replace shallowCopy for ARC/ORC

This commit is contained in:
xflywind 2022-08-29 21:11:11 +08:00 committed by flyx
parent c7d8aa6467
commit a5552a1a18
3 changed files with 15 additions and 6 deletions

View File

@ -162,7 +162,10 @@ proc constructChild*(s: var YamlStream, c: ConstructionContext,
c.refs[target] = (tag: yamlTag(YamlNode), p: cast[pointer](result))
var start: Event
shallowCopy(start, s.next())
when defined(gcArc) or defined(gcOrc):
start = s.next()
else:
shallowCopy(start, s.next())
case start.kind
of yamlStartMap:
@ -198,7 +201,10 @@ proc constructChild*(s: var YamlStream, c: ConstructionContext,
result = YamlNode(tag: start.scalarProperties.tag,
kind: yScalar, scalarStyle: start.scalarStyle,
startPos: start.startPos, endPos: start.endPos)
shallowCopy(result.content, start.scalarContent)
when defined(gcArc) or defined(gcOrc):
result.content = move start.scalarContent
else:
shallowCopy(result.content, start.scalarContent)
addAnchor(c, start.scalarProperties.anchor)
of yamlAlias:
result = cast[YamlNode](c.refs.getOrDefault(start.aliasTarget).p)

View File

@ -105,14 +105,14 @@ proc next*(s: YamlStream): Event {.raises: [YamlStreamError], gcSafe.} =
e.parent = cur
raise e
proc peek*(s: YamlStream): Event {.raises: [YamlStreamError].} =
proc peek*(s: YamlStream): lent Event {.raises: [YamlStreamError].} =
## Get the next item of the stream without advancing the stream.
## Requires ``finished(s) == true``. Handles exceptions of the backend like
## ``next()``.
if not s.peeked:
s.cached = s.next()
s.peeked = true
shallowCopy(result, s.cached)
result = s.cached
proc `peek=`*(s: YamlStream, value: Event) {.raises: [].} =
## Set the next item of the stream. Will replace a previously peeked item,

View File

@ -21,7 +21,7 @@ type Level = tuple[node: JsonNode, key: string, expKey: bool]
proc initLevel(node: JsonNode): Level {.raises: [].} =
(node: node, key: "", expKey: true)
proc jsonFromScalar(content: string, tag: Tag): JsonNode
proc jsonFromScalar(content: sink string, tag: Tag): JsonNode
{.raises: [YamlConstructionError].}=
new(result)
var mappedType: TypeHint
@ -66,7 +66,10 @@ proc jsonFromScalar(content: string, tag: Tag): JsonNode
result = JsonNode(kind: JNull)
else:
result = JsonNode(kind: JString)
shallowCopy(result.str, content)
when defined(gcArc) or defined(gcOrc):
result.str = content
else:
shallowCopy(result.str, content)
except ValueError:
var e = newException(YamlConstructionError, "Cannot parse numeric value")
e.parent = getCurrentException()