cowrcstr: Move owned variant drop out of line. - #451
Merged
Conversation
This reduces the amount of drop glue that the compiler emits for each token significantly, and the owned variant is supposed to be rare already (escaped strings and such). It'd be better to somehow coalesce the drop of all the variants because there's at most one CowRcStr per token, but it's annoying to do so without changing the shape of Token as a whole / the ergonomics of the library. This still gives a good targeted win.
emilio
enabled auto-merge
August 30, 2026 14:06
mrobinson
approved these changes
Aug 30, 2026
| #[cold] | ||
| #[inline(never)] | ||
| unsafe fn drop_slow(ptr: *const String) { | ||
| mem::drop(Rc::from_raw(ptr)) |
Member
There was a problem hiding this comment.
I would surround this with unsafe, to avoid a warning on some versions of Rust.
Suggested change
| mem::drop(Rc::from_raw(ptr)) | |
| unsafe { mem::drop(Rc::from_raw(ptr)) }; |
Member
Author
There was a problem hiding this comment.
Gah, sorry, the auto-merge stuff. Will do :(
Member
Author
There was a problem hiding this comment.
Though IIRC I tested this with nightly and it didn't warn, is it edition dependent or something?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This reduces the amount of drop glue that the compiler emits for each token significantly, and the owned variant is supposed to be rare already (escaped strings and such).
It'd be better to somehow coalesce the drop of all the variants because there's at most one CowRcStr per token, but it's annoying to do so without changing the shape of Token as a whole / the ergonomics of the library. This still gives a good targeted win.