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

Construction from a Ptr{UInt8} #8

Closed
oxinabox opened this issue Oct 5, 2021 · 4 comments · Fixed by #11
Closed

Construction from a Ptr{UInt8} #8

oxinabox opened this issue Oct 5, 2021 · 4 comments · Fixed by #11

Comments

@oxinabox
Copy link

oxinabox commented Oct 5, 2021

Base provides unsafe_string(::Ptr{UInt8}, num_bytes)::String
It would be nice to have a similar function for creating a InlineString that avoids ever allocating memory.

@quinnj
Copy link
Member

quinnj commented Oct 5, 2021

yeah, this would be trivial to add; if someone wants to take a stab at it, we already have the InlineString constructor from bytes::Vector{UInt8} plus pos and len that basically does this.

@oxinabox
Copy link
Author

oxinabox commented Oct 5, 2021

The hard bit though is naming

unsafe_inlinestring?

@quinnj
Copy link
Member

quinnj commented Oct 7, 2021

Personally I'm fine just having this be another constructor and we can add big scary all-caps letters that it's unsafe if the Ptr is invalid.

quinnj added a commit that referenced this issue Oct 19, 2021
Added docs around this new construction path. Added tests as well. The
constructor from pointer just iteratively calls `addcodeunit` since it
seems too much of a hassle to try and do our `unsafe_load` trick on the
full `Ptr{InlineString}` and ensure the memory would be aligned and
enough, etc. This path is much safer and should be pretty performant.
Closed #8.
@quinnj
Copy link
Member

quinnj commented Oct 19, 2021

PR is up: #11

quinnj added a commit that referenced this issue Oct 19, 2021
* Allow construction of InlineStrings from pointer + optional length

Added docs around this new construction path. Added tests as well. The
constructor from pointer just iteratively calls `addcodeunit` since it
seems too much of a hassle to try and do our `unsafe_load` trick on the
full `Ptr{InlineString}` and ensure the memory would be aligned and
enough, etc. This path is much safer and should be pretty performant.
Closed #8.

* fix tests
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 a pull request may close this issue.

2 participants