diff options
-rw-r--r-- | compiler/cgen.nim | 10 | ||||
-rw-r--r-- | compiler/ropes.nim | 13 |
2 files changed, 8 insertions, 15 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 8c6946300..fe5c253dd 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -216,13 +216,9 @@ macro ropecg(m: BModule, frmt: static[FormatStr], args: untyped): Rope = elif frmt[i] == '#' and frmt[i+1] == '#': inc(i, 2) strLit.add("#") - - var start = i - while i < frmt.len: - if frmt[i] != '$' and frmt[i] != '#': inc(i) - else: break - if i - 1 >= start: - strLit.add(substr(frmt, start, i - 1)) + else: + strLit.add(frmt[i]) + inc(i) flushStrLit() result.add newCall(ident"rope", resVar) diff --git a/compiler/ropes.nim b/compiler/ropes.nim index 5bf154393..e96a3ed3a 100644 --- a/compiler/ropes.nim +++ b/compiler/ropes.nim @@ -21,8 +21,8 @@ type # though it is not necessary) Rope* = string -proc newRopeAppender*(): string {.inline.} = - result = newString(0) +proc newRopeAppender*(cap = 80): string {.inline.} = + result = newStringOfCap(cap) proc freeze*(r: Rope) {.inline.} = discard @@ -102,12 +102,9 @@ proc runtimeFormat*(frmt: FormatStr, args: openArray[Rope]): Rope = inc(i) else: doAssert false, "invalid format string: " & frmt - var start = i - while i < frmt.len: - if frmt[i] != '$': inc(i) - else: break - if i - 1 >= start: - result.add(substr(frmt, start, i - 1)) + else: + result.add(frmt[i]) + inc(i) proc `%`*(frmt: static[FormatStr], args: openArray[Rope]): Rope = runtimeFormat(frmt, args) |