From 436ec57f830ec3ac8319b368e4b8fc375d3931b9 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 13 Mar 2019 10:05:05 +0100 Subject: [PATCH] seqs.nim: added a remark about C++ optimizers --- lib/core/seqs.nim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/core/seqs.nim b/lib/core/seqs.nim index be2cdcf1ac..fd46b96eb7 100644 --- a/lib/core/seqs.nim +++ b/lib/core/seqs.nim @@ -36,6 +36,14 @@ when false: proc `=trace`[T](s: NimSeqV2[T]) = 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]) = var x = cast[ptr NimSeqV2[T]](addr s) var p = x.p