This is an archive of the discontinued LLVM Phabricator instance.

[lldb][Module][NFC] Add ModuleList::AnyOf
ClosedPublic

Authored by Michael137 on Dec 1 2022, 1:31 AM.

Diff Detail

Event Timeline

Michael137 created this revision.Dec 1 2022, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 1:31 AM
Michael137 requested review of this revision.Dec 1 2022, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 1:31 AM
This comment was removed by Michael137.

This is definitely useful — I just have one question: Isn't ForEach a special case of AnyOf? Could we implement on in terms of the other?

lldb/include/lldb/Core/ModuleList.h
480

Why not std::function<bool(const lldb::Module &)> ?

Michael137 added inline comments.Dec 1 2022, 12:57 PM
lldb/include/lldb/Core/ModuleList.h
480

Unfortunately a lot of APIs of Module are non-const since they rely on updating internal state :(

Michael137 added a comment.EditedDec 1 2022, 1:02 PM

This is definitely useful — I just have one question: Isn't ForEach a special case of AnyOf? Could we implement on in terms of the other?

Yup it is. But it looked a bit too clever:

bool ret = false;
ForEach([&](auto const& module) {
    if (callback(module)) {
        ret = true;
        return false;
    }

    return true;
}

return ret;

Just iterating over m_modules seemed cleaner.

lldb/include/lldb/Core/ModuleList.h
480

Re. why shared_ptr, that's because I just waned to align it with ForEach. I suppose if we're starting fresh we could just pass the reference. It would have to be mutable though

Michael137 updated this revision to Diff 479444.Dec 1 2022, 2:51 PM
  • Reference insstead of shared_ptr
aprantl accepted this revision.Dec 1 2022, 3:55 PM
aprantl added inline comments.
lldb/source/Core/ModuleList.cpp
1079

module

This revision is now accepted and ready to land.Dec 1 2022, 3:55 PM
This revision was automatically updated to reflect the committed changes.