-
Notifications
You must be signed in to change notification settings - Fork 288
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 Bytes::is_unique
#643
add Bytes::is_unique
#643
Conversation
src/bytes.rs
Outdated
let kind = shared as usize & KIND_MASK; | ||
|
||
if kind == KIND_ARC { | ||
let ref_cnt = unsafe { (*shared.cast::<Shared>()).ref_cnt.load(Ordering::Relaxed) }; |
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.
I am unsure if Relaxed
is correct here
I think there might be an issue with this api: if |
Ah, like if it was an |
I was thinking about |
Normally you would add a method to the vtable and call it, rather than compare with the different vtables. That makes it more difficult to add more vtables in the future. |
Makes sense. One moment, then. |
You can add a comment that mentions that this could happen if the |
I agreed with the |
I have detailed my motivation for this in hyperium/http#662 |
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.
Please add tests for this. I'd like to include one test for each of the following cases:
- Backed by static slice.
- Promotable vtable with
KIND_VEC
. - Promotable vtable with
KIND_ARC
. - Shared vtable.
Other than testing, I think this is ready to be merged.
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.
Your tests are excellent, thanks.
Closes #533
This adds the
is_unique
method toBytes
. It checks reference count when backed by (effectively)Arc<Vec<u8>>
, returns true when backed by a vec, and returns false for static slices