From b5aafb4cf34eeeb89d3dffa1184b11f11bd16a27 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 2 Jan 2012 23:53:07 +0100 Subject: bugfix: +1 unnecessary in resizeString; caused annoying reallocations for strings created with 'newStringOfCap' --- lib/system/alloc.nim | 2 +- lib/system/sysstr.nim | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 8522e6877..8bf173fc1 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2011 Andreas Rumpf +# (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 43ad02575..4fcc7cd3e 100755 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -50,7 +50,7 @@ proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} = result = rawNewString(len) result.len = len c_memcpy(result.data, addr(s.data[start]), len * sizeof(Char)) - result.data[len] = '\0' + #result.data[len] = '\0' else: result = rawNewString(len) @@ -61,7 +61,7 @@ proc toNimStr(str: CString, len: int): NimString {.compilerProc.} = result = rawNewString(len) result.len = len c_memcpy(result.data, str, (len+1) * sizeof(Char)) - result.data[len] = '\0' # readline relies on this! + #result.data[len] = '\0' # readline relies on this! proc cstrToNimstr(str: CString): NimString {.compilerProc.} = result = toNimstr(str, c_strlen(str)) @@ -146,10 +146,10 @@ proc addChar(s: NimString, c: char): NimString = # s = rawNewString(0); proc resizeString(dest: NimString, addlen: int): NimString {.compilerproc.} = - if dest.len + addLen + 1 <= dest.space: + if dest.len + addLen <= dest.space: result = dest else: # slow path: - var sp = max(resize(dest.space), dest.len + addLen + 1) + var sp = max(resize(dest.space), dest.len + addLen) result = cast[NimString](growObj(dest, sizeof(TGenericSeq) + (sp+1) * sizeof(Char))) result.space = sp -- cgit 1.4.1-2-gfad0