Skip to content

Commit

Permalink
remove the use of String's len field (introduced in #22133)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Jul 11, 2017
1 parent 73efb99 commit ba16e8b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,17 @@ hex(n::BigInt, pad::Int) = base(16, n, pad)
function base(b::Integer, n::BigInt, pad::Integer=1)
b < 0 && return base(Int(b), n, pad, (b>0) & (n.size<0))
2 <= b <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $b"))
iszero(n) && pad < 1 && return ""
nd1 = ndigits(n, b)
nd = max(nd1, pad)
str = Base._string_n(nd + isneg(n) + 1) # +1 for final '\0'
ptr = pointer(str)
sv = Base.StringVector(nd + isneg(n))
ptr = pointer(sv)
MPZ.get_str!(ptr + nd - nd1, b, n)
for i = (0:nd-nd1-1) + isneg(n)
unsafe_store!(ptr+i, '0' % UInt8)
end
isneg(n) && unsafe_store!(ptr, '-' % UInt8)
str.len -= 1 # final '\0'
iszero(n) && pad < 1 && (str.len -= 1)
str
String(sv)
end

function ndigits0zpb(x::BigInt, b::Integer)
Expand Down

0 comments on commit ba16e8b

Please sign in to comment.