This is an archive of the discontinued LLVM Phabricator instance.

[clang][Diagnostics][NFC] Remove unnecessary StringRef
ClosedPublic

Authored by tbaeder on May 24 2023, 12:00 AM.

Details

Summary

Seems unnecessary to create a StringRef here just so we can drop the trailing null bytes. We can do that with the std::string we create anyway.

Diff Detail

Event Timeline

tbaeder created this revision.May 24 2023, 12:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 12:00 AM
tbaeder requested review of this revision.May 24 2023, 12:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 12:00 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder updated this revision to Diff 525031.May 24 2023, 12:04 AM
aaron.ballman accepted this revision.May 24 2023, 5:09 AM

LGTM, but it's worth noting that std::string::pop_back() calls erase() and there's no guarantee that there's not an extra allocation involved as a result. However, I've not seen evidence that STLs actually do an allocation (looking at libc++ and MSVC STL, they don't appear to allocate), so I think this is fine.

This revision is now accepted and ready to land.May 24 2023, 5:09 AM

LGTM, but it's worth noting that std::string::pop_back() calls erase() and there's no guarantee that there's not an extra allocation involved as a result. However, I've not seen evidence that STLs actually do an allocation (looking at libc++ and MSVC STL, they don't appear to allocate), so I think this is fine.

Is the allocation only relevant for performance reasons or something else?

LGTM, but it's worth noting that std::string::pop_back() calls erase() and there's no guarantee that there's not an extra allocation involved as a result. However, I've not seen evidence that STLs actually do an allocation (looking at libc++ and MSVC STL, they don't appear to allocate), so I think this is fine.

Is the allocation only relevant for performance reasons or something else?

Performance was my only concern there.

LGTM, but it's worth noting that std::string::pop_back() calls erase() and there's no guarantee that there's not an extra allocation involved as a result. However, I've not seen evidence that STLs actually do an allocation (looking at libc++ and MSVC STL, they don't appear to allocate), so I think this is fine.

Is the allocation only relevant for performance reasons or something else?

Performance was my only concern there.

Okay, good. I don't think that's too bad since the common line of code has exactly 0 trailing null bytes anyway.

This revision was automatically updated to reflect the committed changes.