mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
remove shallowCopy for ARC/ORC (#20070)
* remove shallowCopy for ARC/ORC * use move * fix * more fixes * typo * Update lib/system.nim * follow * add nodestroy * move * copy string * add a changelog entry Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
@@ -170,7 +170,7 @@ proc processRequest(
|
||||
server: AsyncHttpServer,
|
||||
req: FutureVar[Request],
|
||||
client: AsyncSocket,
|
||||
address: string,
|
||||
address: sink string,
|
||||
lineFut: FutureVar[string],
|
||||
callback: proc (request: Request): Future[void] {.closure, gcsafe.},
|
||||
): Future[bool] {.async.} =
|
||||
@@ -184,7 +184,10 @@ proc processRequest(
|
||||
# \n
|
||||
request.headers.clear()
|
||||
request.body = ""
|
||||
request.hostname.shallowCopy(address)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
request.hostname = address
|
||||
else:
|
||||
request.hostname.shallowCopy(address)
|
||||
assert client != nil
|
||||
request.client = client
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ proc load*[T](s: Stream, data: var T) =
|
||||
var tab = initTable[BiggestInt, pointer]()
|
||||
loadAny(s, toAny(data), tab)
|
||||
|
||||
proc store*[T](s: Stream, data: T) =
|
||||
proc store*[T](s: Stream, data: sink T) =
|
||||
## Stores `data` into the stream `s`. Raises `IOError` in case of an error.
|
||||
runnableExamples:
|
||||
import std/streams
|
||||
@@ -301,13 +301,16 @@ proc store*[T](s: Stream, data: T) =
|
||||
|
||||
var stored = initIntSet()
|
||||
var d: T
|
||||
shallowCopy(d, data)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
d = data
|
||||
else:
|
||||
shallowCopy(d, data)
|
||||
storeAny(s, toAny(d), stored)
|
||||
|
||||
proc loadVM[T](typ: typedesc[T], x: T): string =
|
||||
discard "the implementation is in the compiler/vmops"
|
||||
|
||||
proc `$$`*[T](x: T): string =
|
||||
proc `$$`*[T](x: sink T): string =
|
||||
## Returns a string representation of `x` (serialization, marshalling).
|
||||
##
|
||||
## **Note:** to serialize `x` to JSON use `%x` from the `json` module
|
||||
@@ -327,7 +330,10 @@ proc `$$`*[T](x: T): string =
|
||||
else:
|
||||
var stored = initIntSet()
|
||||
var d: T
|
||||
shallowCopy(d, x)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
d = x
|
||||
else:
|
||||
shallowCopy(d, x)
|
||||
var s = newStringStream()
|
||||
storeAny(s, toAny(d), stored)
|
||||
result = s.data
|
||||
|
||||
@@ -464,17 +464,16 @@ proc low*(x: string): int {.magic: "Low", noSideEffect.}
|
||||
## var str = "Hello world!"
|
||||
## low(str) # => 0
|
||||
|
||||
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||
## Use this instead of `=` for a `shallow copy`:idx:.
|
||||
##
|
||||
## The shallow copy only changes the semantics for sequences and strings
|
||||
## (and types which contain those).
|
||||
##
|
||||
## Be careful with the changed semantics though!
|
||||
## There is a reason why the default assignment does a deep copy of sequences
|
||||
## and strings.
|
||||
##
|
||||
## .. warning:: `shallowCopy` does a deep copy with ARC/ORC.
|
||||
when not defined(gcArc) and not defined(gcOrc):
|
||||
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||
## Use this instead of `=` for a `shallow copy`:idx:.
|
||||
##
|
||||
## The shallow copy only changes the semantics for sequences and strings
|
||||
## (and types which contain those).
|
||||
##
|
||||
## Be careful with the changed semantics though!
|
||||
## There is a reason why the default assignment does a deep copy of sequences
|
||||
## and strings.
|
||||
|
||||
# :array|openArray|string|seq|cstring|tuple
|
||||
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
||||
@@ -492,9 +491,12 @@ proc arrPut[I: Ordinal;T,S](a: T; i: I;
|
||||
proc `=destroy`*[T](x: var T) {.inline, magic: "Destroy".} =
|
||||
## Generic `destructor`:idx: implementation that can be overridden.
|
||||
discard
|
||||
proc `=sink`*[T](x: var T; y: T) {.inline, magic: "Asgn".} =
|
||||
proc `=sink`*[T](x: var T; y: T) {.inline, nodestroy, magic: "Asgn".} =
|
||||
## Generic `sink`:idx: implementation that can be overridden.
|
||||
shallowCopy(x, y)
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
x = y
|
||||
else:
|
||||
shallowCopy(x, y)
|
||||
|
||||
when defined(nimHasTrace):
|
||||
proc `=trace`*[T](x: var T; env: pointer) {.inline, magic: "Trace".} =
|
||||
@@ -2852,7 +2854,10 @@ when hasAlloc or defined(nimscript):
|
||||
setLen(x, xl+item.len)
|
||||
var j = xl-1
|
||||
while j >= i:
|
||||
shallowCopy(x[j+item.len], x[j])
|
||||
when defined(gcArc) or defined(gcOrc):
|
||||
x[j+item.len] = move x[j]
|
||||
else:
|
||||
shallowCopy(x[j+item.len], x[j])
|
||||
dec(j)
|
||||
j = 0
|
||||
while j < item.len:
|
||||
|
||||
Reference in New Issue
Block a user