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 support for holding Arc<str> as a new repr? #355

Open
NobodyXu opened this issue Jan 4, 2024 · 3 comments
Open

Add support for holding Arc<str> as a new repr? #355

NobodyXu opened this issue Jan 4, 2024 · 3 comments

Comments

@NobodyXu
Copy link
Contributor

NobodyXu commented Jan 4, 2024

I think it makes sense to support Arc<str> in CompactString as a new repr, it would then enable O(1) cloning, which is very handy for parser/configuration.

@NobodyXu NobodyXu changed the title Add support for holding Arc<str> in Comapct Add support for holding Arc<str> as a new repr? Jan 4, 2024
@dragazo
Copy link
Contributor

dragazo commented Jan 31, 2024

Just noting that if this gets added, there would need to be a fallback to Rc<str> on systems without #[cfg(target_has_atomic = "ptr")] (docs). Or maybe better, support Rc<str> on all platforms and just conditionally also support Arc<str> on platforms that allow it.

@NobodyXu
Copy link
Contributor Author

Thx, I forgot existence of Rc<str> and problems of atomics not present for a while.

While I agree it'd be a good idea, supporting Rc<str> means CompactString would no longer be Send.

We can conditionally support Arc<str> on platforms that support it, and for other platforms, IMO it's Arc<T>'s job to fallback to Rc<T> implementation, because we don't know if it's safe to fallback to it (only when the program is single-threaded).

@dragazo
Copy link
Contributor

dragazo commented Jan 31, 2024

Ah, that's true, and a fallback to Rc<str> would also break Send. In that case, it might be best to just support Arc<str> when it exists on the arch and just not allow that (with no fallback) otherwise.

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

No branches or pull requests

2 participants