This is an archive of the discontinued LLVM Phabricator instance.

[llvm][Support] Avoid intermediate heap allocations in `StringSaver`
ClosedPublic

Authored by jansvoboda11 on Aug 3 2023, 10:20 AM.

Details

Summary

The Twine::str() function currently always allocates heap memory via std::string. However, some instances of Twine don't need an intermediate buffer at all, and the rest can attempt to print into a stack buffer first.

This is intentionally not making use of Twine::isSingleStringLiteral() from D157010 to skip saving the string in the bump-pointer allocator, since the StringSaver documentation suggests that MUST happen for every given string.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Aug 3 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 10:20 AM
jansvoboda11 requested review of this revision.Aug 3 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 10:20 AM
jansvoboda11 edited the summary of this revision. (Show Details)Aug 3 2023, 10:22 AM
jansvoboda11 edited the summary of this revision. (Show Details)
jansvoboda11 retitled this revision from [llvm][Support] Avoid heap allocations in `StringSaver` to [llvm][Support] Avoid intermediate heap allocations in `StringSaver`.Aug 3 2023, 10:25 AM
benlangmuir accepted this revision.Aug 3 2023, 10:37 AM
This revision is now accepted and ready to land.Aug 3 2023, 10:37 AM
This revision was landed with ongoing or failed builds.Aug 3 2023, 11:12 AM
This revision was automatically updated to reflect the committed changes.