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>
This commit is contained in:
Clyybber 2021-06-28 15:00:14 +02:00 • committed by GitHub
commit 6e74fecb42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 68 deletions

View file

@ -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)