Skip to content

cowrcstr: Move owned variant drop out of line. - #451

Merged
emilio merged 1 commit into
mainfrom
cowrcstr-ool-drop
Aug 30, 2026
Merged

cowrcstr: Move owned variant drop out of line.#451
emilio merged 1 commit into
mainfrom
cowrcstr-ool-drop

Conversation

@emilio

@emilio emilio commented Aug 30, 2026

Copy link
Copy Markdown
Member

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.

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.
Comment thread src/cow_rc_str.rs
#[cold]
#[inline(never)]
unsafe fn drop_slow(ptr: *const String) {
mem::drop(Rc::from_raw(ptr))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)) };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Gah, sorry, the auto-merge stuff. Will do :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Though IIRC I tested this with nightly and it didn't warn, is it edition dependent or something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(Yes: #453)

@emilio
emilio added this pull request to the merge queue Aug 30, 2026
Merged via the queue into main with commit b708afd Aug 30, 2026
14 checks passed
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.

2 participants