summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAmjad Ben Hedhili <amjadhedhili@outlook.com>2023-03-13 17:32:20 +0100
committerGitHub <noreply@github.com>2023-03-13 17:32:20 +0100
commit26b7a74a45059453b42f8eee4ccf0586b9003087 (patch)
tree1fc86156b970fbed4bd628fb784322447d69a34b
parentc52e44d8459c04387940bc95e90ed36877466fac (diff)
downloadNim-26b7a74a45059453b42f8eee4ccf0586b9003087.tar.gz
Optimize `cgen.addIndent` (#21508)
* Optimize `cgen.addIndent`

* Avoid temporaries
-rw-r--r--compiler/cgen.nim8
1 files 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..<p.blocks.len:
-    result.add "\t".rope
+  var i = result.len
+  let newLen = i + p.blocks.len
+  result.setLen newLen
+  while i < newLen:
+    result[i] = '\t'
+    inc i
 
 template appcg(m: BModule, c: var Rope, frmt: FormatStr,
            args: untyped) =