newStringOfCap implemented and used to optimize some procs

This commit is contained in:
Araq 2011-05-08 17:38:34 +02:00
commit d2e2d71d05
10 changed files with 53 additions and 21 deletions

View file

@ -620,7 +620,8 @@ proc nl(s: var string, ml: bool) =
proc escapeJson*(s: string): string =
## Converts a string `s` to its JSON representation.
result = "\""
result = newStringOfCap(s.len + s.len shr 3)
result.add("\"")
for x in runes(s):
var r = int(x)
if r >= 32 and r <= 127: