This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] ConstString methods should take StringRefs by value
ClosedPublic

Authored by bulbazord on Jun 2 2023, 10:22 AM.

Details

Summary

StringRef was made to be passed by value efficiently.

Diff Detail

Event Timeline

bulbazord created this revision.Jun 2 2023, 10:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2023, 10:22 AM
bulbazord requested review of this revision.Jun 2 2023, 10:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2023, 10:22 AM
kastiglione added inline comments.Jun 2 2023, 10:24 AM
lldb/source/Utility/ConstString.cpp
305–306

I think the const can be removed too, since StringRefs are immutable.

bulbazord added inline comments.Jun 2 2023, 10:27 AM
lldb/source/Utility/ConstString.cpp
305–306

Yeah, I can remove const and that should be fine too. But StringRef objects aren't immutable, you can modify them with methods like consume_front and consume_back.

kastiglione added inline comments.Jun 2 2023, 10:31 AM
lldb/source/Utility/ConstString.cpp
305–306

thanks for pointing that out, I was thinking about the underlying char *, which isn't mutable. Now that the StringRef is passed by copy, then the caller's copy can't be modified.

bulbazord updated this revision to Diff 527908.Jun 2 2023, 10:43 AM

Remove const where unneeded.

kastiglione accepted this revision.Jun 2 2023, 11:29 AM
This revision is now accepted and ready to land.Jun 2 2023, 11:29 AM
fdeazeve accepted this revision.Jun 2 2023, 2:24 PM

LGTM, thanks for picking this up!