From c52e44d8459c04387940bc95e90ed36877466fac Mon Sep 17 00:00:00 2001 From: Amjad Ben Hedhili Date: Mon, 13 Mar 2023 08:43:45 +0100 Subject: [PATCH 1/2] Add `cursor` annotations to lists iterator variables (#21507) Add `cursor` annotations to iterator variables * See https://nim-lang.github.io/Nim/destructors.html#the-cursor-pragma --- lib/pure/collections/lists.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/collections/lists.nim b/lib/pure/collections/lists.nim index a08c62964..6e3ddf397 100644 --- a/lib/pure/collections/lists.nim +++ b/lib/pure/collections/lists.nim @@ -188,13 +188,13 @@ func toDoublyLinkedList*[T](elems: openArray[T]): DoublyLinkedList[T] {.since: ( result.add(elem) template itemsListImpl() {.dirty.} = - var it = L.head + var it {.cursor.} = L.head while it != nil: yield it.value it = it.next template itemsRingImpl() {.dirty.} = - var it = L.head + var it {.cursor.} = L.head if it != nil: while true: yield it.value From 26b7a74a45059453b42f8eee4ccf0586b9003087 Mon Sep 17 00:00:00 2001 From: Amjad Ben Hedhili Date: Mon, 13 Mar 2023 17:32:20 +0100 Subject: [PATCH 2/2] Optimize `cgen.addIndent` (#21508) * Optimize `cgen.addIndent` * Avoid temporaries --- compiler/cgen.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index d2095016c..5ba68580d 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -228,8 +228,12 @@ macro ropecg(m: BModule, frmt: static[FormatStr], args: untyped): Rope = result.add newCall(ident"rope", resVar) proc addIndent(p: BProc; result: var Rope) = - for i in 0..