Skip to content
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

Support CodeUnits as valid input for CSV.File/CSV.Rows #905

Merged
merged 1 commit into from
Sep 15, 2021
Merged

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Sep 15, 2021

Fixes #894. I believe this used to work because we made a copy of the
input CodeUnits object, which is fine, because we got a
Vector{UInt8} out of it, but not ideal since we made a copy. After
some research, I found that when you call IOBuffer(str), it uses this
nifty little trick of calling unsafe_wrap(Vector{UInt8}, str) which is
then passed to IOBuffer as a way to convert a string to a
Vector{UInt8} without copying. We can utilize the same trick to
efficiently treat a string as a Vector{UInt8} while the Julia
internals takes care of tracking the true owner of the data as the
original string for us (thus avoiding any GC issues if we were to
naively call unsafe_wrap(Array, pointer(str)) ourselves).

Fixes #894. I believe this used to work because we made a copy of the
input `CodeUnits` object, which is fine, because we got a
`Vector{UInt8}` out of it, but not ideal since we made a copy. After
some research, I found that when you call `IOBuffer(str)`, it uses this
nifty little trick of calling `unsafe_wrap(Vector{UInt8}, str)` which is
then passed to `IOBuffer` as a way to convert a string to a
`Vector{UInt8}` without copying. We can utilize the same trick to
efficiently treat a string as a `Vector{UInt8}` while the Julia
internals takes care of tracking the true owner of the data as the
original string for us (thus avoiding any GC issues if we were to
naively call `unsafe_wrap(Array, pointer(str))` ourselves).
@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #905 (6c616e9) into main (b0032e8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #905   +/-   ##
=======================================
  Coverage   89.68%   89.69%           
=======================================
  Files           9        9           
  Lines        2181     2183    +2     
=======================================
+ Hits         1956     1958    +2     
  Misses        225      225           
Impacted Files Coverage Δ
src/CSV.jl 80.00% <ø> (ø)
src/file.jl 95.83% <ø> (ø)
src/rows.jl 78.01% <ø> (ø)
src/utils.jl 85.08% <100.00%> (+0.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0032e8...6c616e9. Read the comment docs.

@quinnj quinnj merged commit c3af297 into main Sep 15, 2021
@quinnj quinnj deleted the jq/894 branch September 15, 2021 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CodeUnits input broken with CSV.jl 0.9
1 participant