mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-19 21:31:39 +00:00
refactor: replace elemSupportsCopyMem with supportsCopyMem for clarity and consistency
This commit is contained in:
@@ -620,12 +620,6 @@ proc checkSelfAssignment(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
cond.typ = getSysType(c.g, c.info, tyBool)
|
||||
body.add genIf(c, cond, newTreeI(nkReturnStmt, c.info, newNodeI(nkEmpty, c.info)))
|
||||
|
||||
proc elemSupportsCopyMem(t: PType): bool =
|
||||
## Returns true if the element type of seq `t` supports bulk memory copy
|
||||
## (i.e., has no GC refs and no destructors).
|
||||
let elemType = t.elementType.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
|
||||
result = not containsGarbageCollectedRef(elemType) and not hasDestructor(elemType)
|
||||
|
||||
proc genBulkCopySeq(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
## Generates a call to nimCopySeqPayload for bulk memcpy of seq data.
|
||||
let elemType = t.elementType
|
||||
@@ -650,7 +644,7 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
case c.kind
|
||||
of attachedDup:
|
||||
body.add setLenSeqCall(c, t, x, y)
|
||||
if elemSupportsCopyMem(t):
|
||||
if supportsCopyMem(t):
|
||||
genBulkCopySeq(c, t, body, x, y)
|
||||
else:
|
||||
forallElements(c, t, body, x, y)
|
||||
@@ -665,7 +659,7 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
# For trivially copyable types, use bulk copyMem instead of element loop.
|
||||
checkSelfAssignment(c, t, body, x, y)
|
||||
body.add setLenSeqCall(c, t, x, y)
|
||||
if elemSupportsCopyMem(t):
|
||||
if supportsCopyMem(t):
|
||||
genBulkCopySeq(c, t, body, x, y)
|
||||
else:
|
||||
forallElements(c, t, body, x, y)
|
||||
|
||||
@@ -232,9 +232,7 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
|
||||
of "stripGenericParams":
|
||||
result = uninstantiate(operand).toNode(traitCall.info)
|
||||
of "supportsCopyMem":
|
||||
let t = operand.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
|
||||
let complexObj = containsGarbageCollectedRef(t) or
|
||||
hasDestructor(t)
|
||||
let complexObj = supportsCopyMem(operand)
|
||||
result = newIntNodeT(toInt128(ord(not complexObj)), traitCall, c.idgen, c.graph)
|
||||
of "canFormCycles":
|
||||
result = newIntNodeT(toInt128(ord(types.canFormAcycle(c.graph, operand))), traitCall, c.idgen, c.graph)
|
||||
|
||||
@@ -1779,3 +1779,8 @@ proc reduceToBase*(f: PType): PType =
|
||||
result = f.elementType
|
||||
else:
|
||||
result = f
|
||||
|
||||
proc supportsCopyMem*(t: PType): bool =
|
||||
let t = t.skipTypes({tyVar, tyLent, tyGenericInst, tyAlias, tySink, tyInferred})
|
||||
result = containsGarbageCollectedRef(t) or
|
||||
hasDestructor(t)
|
||||
|
||||
Reference in New Issue
Block a user