Skip to content

Commit

Permalink
Use ByteArray.reverse in Int.to_base
Browse files Browse the repository at this point in the history
This reduces the amount of allocations needed by Int.to_base.

Changelog: performance
  • Loading branch information
yorickpeterse committed Oct 11, 2022
1 parent d9c0d64 commit 47c7669
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions libstd/src/std/int.inko
Expand Up @@ -205,19 +205,18 @@ class builtin Int {
if self == 0 { return '0' }

let alphabet = '0123456789abcdef'
let bytes = []
let bytes = ByteArray.new
let mut int = absolute

while int > 0 {
bytes.push(alphabet.byte(int % base))

int /= base
}

if self < 0 { bytes.push(45) }
if self < 0 { bytes.push(0x2D) }

bytes.reverse
ByteArray.from_array(bytes).into_string
bytes.into_string
}

# Returns the result of performing a bitwise `NOT` on `self`.
Expand Down

0 comments on commit 47c7669

Please sign in to comment.