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()