From a5552a1a18bdb7b8bb95c0d037706874a7d4bfe8 Mon Sep 17 00:00:00 2001 From: xflywind <43030857+ringabout@users.noreply.github.com> Date: Mon, 29 Aug 2022 21:11:11 +0800 Subject: [PATCH] replace shallowCopy for ARC/ORC --- yaml/dom.nim | 10 ++++++++-- yaml/stream.nim | 4 ++-- yaml/tojson.nim | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/yaml/dom.nim b/yaml/dom.nim index d0c5587..9ddf178 100644 --- a/yaml/dom.nim +++ b/yaml/dom.nim @@ -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) diff --git a/yaml/stream.nim b/yaml/stream.nim index 73da22a..aa0fa52 100644 --- a/yaml/stream.nim +++ b/yaml/stream.nim @@ -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, diff --git a/yaml/tojson.nim b/yaml/tojson.nim index 83caec1..f6f6164 100644 --- a/yaml/tojson.nim +++ b/yaml/tojson.nim @@ -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()