summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2021-06-28 15:00:14 +0200
committerGitHub <noreply@github.com>2021-06-28 15:00:14 +0200
commit6e74fecb4275272e5224e2a0ba45df5ca2c40b82 (patch)
tree7c675a2c5cbec85bc586b85bd2ef699049129935 /lib/system
parente720bbdd76303e2cc0a3a169e870859470a1da84 (diff)
downloadNim-6e74fecb4275272e5224e2a0ba45df5ca2c40b82.tar.gz
Simplify addInt, remove digits10 (#18356)
* Simplify addInt, remove digits10

Co-authored-by: Charles Blake <charlechaud@gmail.com>

* Fix bootstrapping

* Add noInit to tmp array

* noInit -> noinit

Co-authored-by: Charles Blake <charlechaud@gmail.com>
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/dollars.nim4
-rw-r--r--lib/system/strmantle.nim10
2 files changed, 4 insertions, 10 deletions
diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim
index 3d824a965..c23ea347d 100644
--- a/lib/system/dollars.nim
+++ b/lib/system/dollars.nim
@@ -7,9 +7,7 @@ proc `$`*(x: int): string {.magic: "IntToStr", noSideEffect.}
   ## spelling `toString`:idx:.
 
 template dollarImpl(x: uint | uint64, result: var string) =
-  let length = digits10(x)
-  setLen(result, length)
-  numToString(result, x, length)
+  addIntImpl(result, x)
 
 when defined(js):
   import std/private/since
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim
index b60bc4b80..63e341763 100644
--- a/lib/system/strmantle.nim
+++ b/lib/system/strmantle.nim
@@ -51,8 +51,6 @@ proc addInt*(result: var string; x: int64) =
   ##     a = "123"
   ##     b = 45
   ##   a.addInt(b) # a <- "12345"
-  let base = result.len
-  var length: int
   var num: uint64
 
   if x < 0:
@@ -60,14 +58,12 @@ proc addInt*(result: var string; x: int64) =
       num = uint64(x)
     else:
       num = uint64(-x)
-    length = base + digits10(num) + 1
-    setLen(result, length)
+    let base = result.len
+    setLen(result, base + 1)
     result[base] = '-'
   else:
     num = uint64(x)
-    length = base + digits10(num)
-    setLen(result, length)
-  numToString(result, num, length)
+  addIntImpl(result, num)
 
 proc nimIntToStr(x: int): string {.compilerRtl.} =
   result = newStringOfCap(sizeof(x)*4)