Skip to content

Add optional support for compact_str::CompactString#112

Open
mcronce wants to merge 1 commit into
SoftbearStudios:mainfrom
mcronce:main
Open

Add optional support for compact_str::CompactString#112
mcronce wants to merge 1 commit into
SoftbearStudios:mainfrom
mcronce:main

Conversation

@mcronce
Copy link
Copy Markdown

@mcronce mcronce commented May 17, 2026

Think I got everything right (it's definitely working for my use case, at least, building against local bitcode) - I have one open question in a // TODO comment, but I suspect the answer is "no we can't" and also "it would hardly make a difference even if we could"

@finnbear
Copy link
Copy Markdown
Member

Thanks! Next time we work on bitcode, we'll review and merge this. Regarding your TODO comment, I don't think it can be optimized. CompactString can be:

  • 'static but, without lifetime specialization and decoding a 'static buffer, it cannot be exploited in bitcode
  • inline but, here, a copy is unavoidable without changing the StrDecoder internals. if you give a &'str internals as if they were for a String, then it will cause a use-after-free when impl Drop for String runs.
  • heap but, here, you must create an allocation where none previously existed

If CompactString had a borrowed variant, like enum CompactString<'a> { Borrowed(&'a str) } (or the branchless equivalent of this) then maybe it could borrow from the buffer.

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