replace shallowcopy with move in ARC/ORC (#20061)

This commit is contained in:
flywind 2022-07-19 03:23:39 +08:00 • committed by GitHub
commit d934ba9326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -218,10 +218,6 @@ proc newJRawNumber(s: string): JsonNode =
## to the string representation without the quotes. ## to the string representation without the quotes.
result = JsonNode(kind: JString, str: s, isUnquoted: true) result = JsonNode(kind: JString, str: s, isUnquoted: true)
proc newJStringMove(s: string): JsonNode =
result = JsonNode(kind: JString)
shallowCopy(result.str, s)
proc newJInt*(n: BiggestInt): JsonNode = proc newJInt*(n: BiggestInt): JsonNode =
## Creates a new `JInt JsonNode`. ## Creates a new `JInt JsonNode`.
result = JsonNode(kind: JInt, num: n) result = JsonNode(kind: JInt, num: n)
@ -859,8 +855,12 @@ proc parseJson(p: var JsonParser; rawIntegers, rawFloats: bool, depth = 0): Json
case p.tok case p.tok
of tkString: of tkString:
# we capture 'p.a' here, so we need to give it a fresh buffer afterwards: # we capture 'p.a' here, so we need to give it a fresh buffer afterwards:
result = newJStringMove(p.a) when defined(gcArc) or defined(gcOrc):
p.a = "" result = JsonNode(kind: JString, str: move p.a)
else:
result = JsonNode(kind: JString)
shallowCopy(result.str, p.a)
p.a = ""
discard getTok(p) discard getTok(p)
of tkInt: of tkInt:
if rawIntegers: if rawIntegers: