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:
parent
e720bbdd76
commit
6e74fecb42
4 changed files with 27 additions and 68 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue