mirror of https://github.com/status-im/NimYAML.git
replace shallowCopy for ARC/ORC
This commit is contained in:
parent
c7d8aa6467
commit
a5552a1a18
10
yaml/dom.nim
10
yaml/dom.nim
|
@ -162,7 +162,10 @@ proc constructChild*(s: var YamlStream, c: ConstructionContext,
|
||||||
c.refs[target] = (tag: yamlTag(YamlNode), p: cast[pointer](result))
|
c.refs[target] = (tag: yamlTag(YamlNode), p: cast[pointer](result))
|
||||||
|
|
||||||
var start: Event
|
var start: Event
|
||||||
shallowCopy(start, s.next())
|
when defined(gcArc) or defined(gcOrc):
|
||||||
|
start = s.next()
|
||||||
|
else:
|
||||||
|
shallowCopy(start, s.next())
|
||||||
|
|
||||||
case start.kind
|
case start.kind
|
||||||
of yamlStartMap:
|
of yamlStartMap:
|
||||||
|
@ -198,7 +201,10 @@ proc constructChild*(s: var YamlStream, c: ConstructionContext,
|
||||||
result = YamlNode(tag: start.scalarProperties.tag,
|
result = YamlNode(tag: start.scalarProperties.tag,
|
||||||
kind: yScalar, scalarStyle: start.scalarStyle,
|
kind: yScalar, scalarStyle: start.scalarStyle,
|
||||||
startPos: start.startPos, endPos: start.endPos)
|
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)
|
addAnchor(c, start.scalarProperties.anchor)
|
||||||
of yamlAlias:
|
of yamlAlias:
|
||||||
result = cast[YamlNode](c.refs.getOrDefault(start.aliasTarget).p)
|
result = cast[YamlNode](c.refs.getOrDefault(start.aliasTarget).p)
|
||||||
|
|
|
@ -105,14 +105,14 @@ proc next*(s: YamlStream): Event {.raises: [YamlStreamError], gcSafe.} =
|
||||||
e.parent = cur
|
e.parent = cur
|
||||||
raise e
|
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.
|
## Get the next item of the stream without advancing the stream.
|
||||||
## Requires ``finished(s) == true``. Handles exceptions of the backend like
|
## Requires ``finished(s) == true``. Handles exceptions of the backend like
|
||||||
## ``next()``.
|
## ``next()``.
|
||||||
if not s.peeked:
|
if not s.peeked:
|
||||||
s.cached = s.next()
|
s.cached = s.next()
|
||||||
s.peeked = true
|
s.peeked = true
|
||||||
shallowCopy(result, s.cached)
|
result = s.cached
|
||||||
|
|
||||||
proc `peek=`*(s: YamlStream, value: Event) {.raises: [].} =
|
proc `peek=`*(s: YamlStream, value: Event) {.raises: [].} =
|
||||||
## Set the next item of the stream. Will replace a previously peeked item,
|
## Set the next item of the stream. Will replace a previously peeked item,
|
||||||
|
|
|
@ -21,7 +21,7 @@ type Level = tuple[node: JsonNode, key: string, expKey: bool]
|
||||||
proc initLevel(node: JsonNode): Level {.raises: [].} =
|
proc initLevel(node: JsonNode): Level {.raises: [].} =
|
||||||
(node: node, key: "", expKey: true)
|
(node: node, key: "", expKey: true)
|
||||||
|
|
||||||
proc jsonFromScalar(content: string, tag: Tag): JsonNode
|
proc jsonFromScalar(content: sink string, tag: Tag): JsonNode
|
||||||
{.raises: [YamlConstructionError].}=
|
{.raises: [YamlConstructionError].}=
|
||||||
new(result)
|
new(result)
|
||||||
var mappedType: TypeHint
|
var mappedType: TypeHint
|
||||||
|
@ -66,7 +66,10 @@ proc jsonFromScalar(content: string, tag: Tag): JsonNode
|
||||||
result = JsonNode(kind: JNull)
|
result = JsonNode(kind: JNull)
|
||||||
else:
|
else:
|
||||||
result = JsonNode(kind: JString)
|
result = JsonNode(kind: JString)
|
||||||
shallowCopy(result.str, content)
|
when defined(gcArc) or defined(gcOrc):
|
||||||
|
result.str = content
|
||||||
|
else:
|
||||||
|
shallowCopy(result.str, content)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
var e = newException(YamlConstructionError, "Cannot parse numeric value")
|
var e = newException(YamlConstructionError, "Cannot parse numeric value")
|
||||||
e.parent = getCurrentException()
|
e.parent = getCurrentException()
|
||||||
|
|
Loading…
Reference in New Issue