-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix deprecations with copy! and Vector{UInt8}(str) #234
Changes from all commits
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
julia 0.6 | ||
Compat 0.44.0 | ||
Compat 0.45.0 | ||
Nullables 0.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,7 @@ function read_unicode_escape!(ps) | |
end | ||
end | ||
|
||
get_bytes(str) = Vector{UInt8}(@static isdefined(Base, :codeunits) ? codeunits(str) : str) | ||
|
||
function parse_string(ps::ParserState) | ||
b = UInt8[] | ||
|
@@ -272,7 +273,7 @@ function parse_string(ps::ParserState) | |
if c == BACKSLASH | ||
c = advance!(ps) | ||
if c == LATIN_U # Unicode escape | ||
append!(b, Vector{UInt8}(string(read_unicode_escape!(ps)))) | ||
append!(b, get_bytes(string(read_unicode_escape!(ps)))) | ||
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.
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. The problem was that 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. Even using 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. Another question - why do you think my change would force a copy? It uses |
||
else | ||
c = get(ESCAPES, c, 0x00) | ||
c == 0x00 && _error(E_BAD_ESCAPE, ps) | ||
|
@@ -381,9 +382,11 @@ function unparameterize_type(T::Type) | |
candidate <: Union{} ? T : candidate | ||
end | ||
|
||
function parse(str::AbstractString; dicttype::Type{<:AbstractDict}=Dict{String,Any}, inttype::Type{<:Real}=Int64) | ||
function parse(str::AbstractString; | ||
dicttype::Type{<:AbstractDict}=Dict{String,Any}, | ||
inttype::Type{<:Real}=Int64) | ||
pc = ParserContext{unparameterize_type(dicttype), inttype}() | ||
ps = MemoryParserState(Vector{UInt8}(String(str)), 1) | ||
ps = MemoryParserState(get_bytes(str), 1) | ||
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. It would be better not to make a copy here. Since 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, but I'm trying to make the minimal changes here (as I was told many times before to do 🙂 ) to make it work on both v0.6 and later. 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. My suggestions require hardly any more code, and don't make more copies. 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. They don't make less copies either. My change actually requires gets rid of the copies on v0.7, and doesn't add them for v0.6. 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. Your version has makes more copies on 0.7 than 0.6, whereas mine does not. 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. On v0.7, it calls |
||
v = parse_value(pc, ps) | ||
chomp_space!(ps) | ||
if hasmore(ps) | ||
|
@@ -392,7 +395,9 @@ function parse(str::AbstractString; dicttype::Type{<:AbstractDict}=Dict{String,A | |
v | ||
end | ||
|
||
function parse(io::IO; dicttype::Type{<:AbstractDict}=Dict{String,Any}, inttype::Type{<:Real}=Int64) | ||
function parse(io::IO; | ||
dicttype::Type{<:AbstractDict}=Dict{String,Any}, | ||
inttype::Type{<:Real}=Int64) | ||
pc = ParserContext{unparameterize_type(dicttype), inttype}() | ||
ps = StreamingParserState(io) | ||
parse_value(pc, ps) | ||
|
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.
This function is not necessary given the changes I suggest below.
However, it would be good to have a
Compat.codeunits(s)
function that just returnsVector{UInt8}(s)
in Julia 0.6.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.
Just pushed a PR for Compat to add
codeunits
andncodeunits
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.
If those are merged soon, then yes, I'll change this to use codeunits.