This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] Refactor Language::GetFormatterPrefixSuffix
ClosedPublic

Authored by bulbazord on May 26 2023, 6:36 PM.

Details

Summary
  • Remove unused parameter valobj (I checked downstream, not even swift is using it).
  • Return a std::pair<StringRef, StringRef> insted of having 2 out parameter strings.
  • Remove the use of ConstStrings.

This change was primarily mechanical except in
ObjCLanguage::GetFormatterPrefixSuffix. To keep this fast, we
construct an llvm::StringMap<std::pair<StringRef, StringRef>> so that we
can look things up quickly. There is some amount of cost to setting up
the map the first time it is called, but subsequent lookups should be
as fast as a hash + string comparison (the cost of looking up something
in an llvm::StringMap).

Diff Detail

Event Timeline

bulbazord created this revision.May 26 2023, 6:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 6:36 PM
bulbazord requested review of this revision.May 26 2023, 6:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 6:36 PM
fdeazeve added inline comments.
lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
1000–1001

We can make this whole map const and remove the explicit call_once by folding the insert calls into the ctor:

static constexpr llvm::StringRef empty;
static const llvm::StringMap<
    std::pair<const llvm::StringRef, const llvm::StringRef>>
    g_affix_map = {{"CFBag", std::make_pair("@", empty)},
                   {"CFBinaryHeap", std::make_pair("@", empty)},
                   ..., };

If you're so inclined, you can even get rid of the final make_pair calls:

static const llvm::StringMap<
    std::pair<const llvm::StringRef, const llvm::StringRef>>
    g_affix_map = {{"CFBag", {"@", empty}},
                   {"CFBinaryHeap", {"@", empty}}};

modulo Felipe's comment, LGTM!

Michael137 accepted this revision.May 30 2023, 8:48 AM
This revision is now accepted and ready to land.May 30 2023, 8:48 AM
bulbazord added inline comments.May 30 2023, 10:18 AM
lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
1000–1001

Oh, this looks much nicer. I'll do it this way!

Remove use of std::call_once where not needed.

bulbazord marked an inline comment as done.May 30 2023, 10:20 AM