seqs.nim: added a remark about C++ optimizers
This commit is contained in:
parent
07f58ddfa9
commit
436ec57f83
1 changed files with 8 additions and 0 deletions
|
|
@ -36,6 +36,14 @@ when false:
|
||||||
proc `=trace`[T](s: NimSeqV2[T]) =
|
proc `=trace`[T](s: NimSeqV2[T]) =
|
||||||
for i in 0 ..< s.len: `=trace`(s.data[i])
|
for i in 0 ..< s.len: `=trace`(s.data[i])
|
||||||
|
|
||||||
|
#[
|
||||||
|
Keep in mind that C optimizers are bad at detecting the connection
|
||||||
|
between ``s.p != nil`` and ``s.len != 0`` and that these are intermingled
|
||||||
|
with user-level code that accesses ``s.len`` only, never ``s.p`` directly.
|
||||||
|
This means the check for whether ``s.p`` needs to be freed should
|
||||||
|
be ``s.len == 0`` even though that feels slightly more awkward.
|
||||||
|
]#
|
||||||
|
|
||||||
proc `=destroy`[T](s: var seq[T]) =
|
proc `=destroy`[T](s: var seq[T]) =
|
||||||
var x = cast[ptr NimSeqV2[T]](addr s)
|
var x = cast[ptr NimSeqV2[T]](addr s)
|
||||||
var p = x.p
|
var p = x.p
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue