[clang] [clang-tools-extra] Remove `StringLiteral` in favor of `StringRef` (PR #122366)
Benoit Jacob via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 13:11:00 PST 2025
bjacob wrote:
@jrtc27
> const char[] allocates storage for the string contents though, so takes up space in memory if the string can be merged with others at compile or link time. There are multiple things being traded off here, and PDE vs PIC/PIE complicates the story further. So it's not just as simple as "use const char[] whenever you can".
Ah, thanks for the explanation... I really hadn't thought of that, but IIUC you're saying that the indirection (referring to a string via a pointer to it) allows merging storage when a string literal is a substring of another, while using raw `const char[]` doesn't allow any reuse unless the string literal exactly match.
Really interesting, but I still wonder -- this sounds like a fancier kind of optimization that probably won't be able to apply in a majority of cases (it needs literals to be substrings of each other?) while the relocations are every single time.
https://github.com/llvm/llvm-project/pull/122366
More information about the cfe-commits
mailing list