This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] Remove use of ConstString from IOHandler
ClosedPublic

Authored by bulbazord on May 26 2023, 3:55 PM.

Details

Summary

None of these need to be in the ConstString StringPool. For the most
part they are constant strings and do not require fast comparisons.

I did change IOHandlerDelegateMultiline slightly -- specifically, the
m_end_line member always has a \n at the end of it now. This was so
that IOHandlerGetControlSequence can always return a StringRef. This
did require a slight change to IOHandlerIsInputComplete where we must
drop the newline before comparing it against the input parameter.

Diff Detail

Event Timeline

bulbazord created this revision.May 26 2023, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 3:55 PM
bulbazord requested review of this revision.May 26 2023, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 3:55 PM
mib added a comment.May 31 2023, 10:25 AM

TBH, it feels like a lot of - risky - changes just so IOHandlerGetControlSequence can return a llvm::StringRef ? Is that really necessary ?

TBH, it feels like a lot of - risky - changes just so IOHandlerGetControlSequence can return a llvm::StringRef ? Is that really necessary ?

I assume you're referring to IOHandlerDelegateMultiline storing its m_end_line member with a newline at the end now? My thought process was this: Pretty much every method changed here returns a constant string except for IOHandlerDelegateMultiline::IOHandlerGetControlSequence. That one creates a brand new string with \n at the end of it, so if m_end_line doesn't have a \n at the end of it, the we must always return a std::string which feels a little wasteful since the majority of these methods hand back a constant string. That also percolates up: IOHandlerGetControlSequence is the "lowest layer" of these call stacks, so whatever it returns is what the others must return as well.

The other option is to change IOHandlerDelegateMultiline to always take a string with a \n, but that is a lot harder to enforce. What do you think? I'm ok making whatever change makes this less risky in a separate commit.

I don't think we need to support the case where the "end line token" doesn't have to stand on its own line. It's reasonable for lldb to impose this policy, and if we are going to do that then requiring the "\n" after the end line token also seems odd. The way this is done seems okay to me.

jingham accepted this revision.Jun 12 2023, 2:07 PM
This revision is now accepted and ready to land.Jun 12 2023, 2:07 PM
JDevlieghere added inline comments.Jun 12 2023, 2:51 PM
lldb/include/lldb/Core/IOHandler.h
110

I would return {} or return "".

297–298

Can we make end_line a StringRef?

bulbazord updated this revision to Diff 530694.Jun 12 2023, 4:05 PM

Address Jonas's comments

bulbazord updated this revision to Diff 530712.Jun 12 2023, 4:49 PM
bulbazord marked an inline comment as done.

Address the other suggestion

bulbazord marked an inline comment as done.Jun 12 2023, 4:50 PM
This revision was automatically updated to reflect the committed changes.