-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
faster String
allocation
#19449
faster String
allocation
#19449
Changes from all commits
e62352b
79bb7be
ce24657
c01a2cf
8c687da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,15 @@ function deepcopy_internal(x::SimpleVector, stackdict::ObjectIdDict) | |
return y | ||
end | ||
|
||
function deepcopy_internal(x::String, stackdict::ObjectIdDict) | ||
if haskey(stackdict, x) | ||
return stackdict[x] | ||
end | ||
y = unsafe_string(pointer(x), sizeof(x)) | ||
stackdict[x] = y | ||
return y | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, I see it here. |
||
|
||
function deepcopy_internal(x::ANY, stackdict::ObjectIdDict) | ||
T = typeof(x)::DataType | ||
nf = nfields(T) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,6 +778,7 @@ export | |
chomp, | ||
chop, | ||
chr2ind, | ||
codeunit, | ||
dec, | ||
digits, | ||
digits!, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,8 +532,10 @@ hex(n::BigInt, pad::Int) = base(16, n, pad) | |
|
||
function base(b::Integer, n::BigInt) | ||
2 <= b <= 62 || throw(ArgumentError("base must be 2 ≤ base ≤ 62, got $b")) | ||
p = ccall((:__gmpz_get_str,:libgmp), Ptr{UInt8}, (Ptr{UInt8}, Cint, Ptr{BigInt}), C_NULL, b, &n) | ||
unsafe_wrap(String, p, true) | ||
nd = ndigits(n, b) | ||
str = Base._string_n(n < 0 ? nd+1 : nd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should something like this be documented and exported? Seems useful for calling C APIs... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that would be fine. Any ideas for a name? |
||
ccall((:__gmpz_get_str,:libgmp), Ptr{UInt8}, (Ptr{UInt8}, Cint, Ptr{BigInt}), str, b, &n) | ||
return str | ||
end | ||
|
||
function base(b::Integer, n::BigInt, pad::Integer) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably mention
sizeof(str)
here too, sincelength(str.data)
is pretty common.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, the
pointer(s.data)
equivalent would also be good mentioning.