Skip to content

Commit

Permalink
improve performance for number to string conversion functions (#28661)
Browse files Browse the repository at this point in the history
* improve performance for number to string conversion functions

(cherry picked from commit 472fe5f)
  • Loading branch information
KristofferC committed Aug 19, 2018
1 parent d01f512 commit a7c4412
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,35 +543,35 @@ function bin(x::Unsigned, pad::Int, neg::Bool)
i = neg + max(pad,sizeof(x)<<3-leading_zeros(x))
a = StringVector(i)
while i > neg
a[i] = '0'+(x&0x1)
@inbounds a[i] = 48+(x&0x1)
x >>= 1
i -= 1
end
if neg; a[1]='-'; end
if neg; @inbounds a[1]=0x2d; end
String(a)
end

function oct(x::Unsigned, pad::Int, neg::Bool)
i = neg + max(pad,div((sizeof(x)<<3)-leading_zeros(x)+2,3))
a = StringVector(i)
while i > neg
a[i] = '0'+(x&0x7)
@inbounds a[i] = 48+(x&0x7)
x >>= 3
i -= 1
end
if neg; a[1]='-'; end
if neg; @inbounds a[1]=0x2d; end
String(a)
end

function dec(x::Unsigned, pad::Int, neg::Bool)
i = neg + ndigits(x, base=10, pad=pad)
a = StringVector(i)
while i > neg
a[i] = '0'+rem(x,10)
@inbounds a[i] = 48+rem(x,10)
x = oftype(x,div(x,10))
i -= 1
end
if neg; a[1]='-'; end
if neg; @inbounds a[1]=0x2d; end
String(a)
end

Expand All @@ -580,11 +580,11 @@ function hex(x::Unsigned, pad::Int, neg::Bool)
a = StringVector(i)
while i > neg
d = x & 0xf
a[i] = '0'+d+39*(d>9)
@inbounds a[i] = 48+d+39*(d>9)
x >>= 4
i -= 1
end
if neg; a[1]='-'; end
if neg; @inbounds a[1]=0x2d; end
String(a)
end

Expand Down

0 comments on commit a7c4412

Please sign in to comment.