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

Add appropriate cconvert/unsafe_convert methods to avoid String alloc… #56

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Nov 17, 2022

…ation in Base

@bkamins
Copy link

bkamins commented Nov 17, 2022

Is this needed for https://github.com/JuliaDatabases/SQLite.jl/pull/308/files to work or this is just extra feature to avoid allocations? (I understand the latter)

@quinnj
Copy link
Member Author

quinnj commented Nov 17, 2022

Correct; just the latter to avoid the default Base definitions for cconvert which materialize the String

Base.cconvert(::Type{Ptr{Int8}}, x::InlineString1) = Ref{InlineString1}(x)
Base.cconvert(::Type{Ptr{UInt8}}, x::T) where {T <: InlineString} =
Ref{T}(_bswap(clear_n_bytes(x, 1)))
Base.cconvert(::Type{Ptr{Int8}}, x::T) where {T <: InlineString} =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to also handle Ptr{Cstring}? how about Cwstring?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good idea. I pushed a cconvert for Cstring; I say we don't worry about Cwstring for now (since InlineStrings by default are utf8 anyway).

src/InlineStrings.jl Outdated Show resolved Hide resolved
@quinnj quinnj merged commit 348f085 into main Nov 18, 2022
@quinnj quinnj deleted the jq-cconvert branch November 18, 2022 01:02
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.

None yet

3 participants