[PATCH] D105218: [llvm-objcopy] Improve performance of long pattern lists
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 09:03:55 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0144e625b967: [llvm-objcopy] Improve performance of long pattern lists (authored by MaskRay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105218/new/
https://reviews.llvm.org/D105218
Files:
llvm/tools/llvm-objcopy/CommonConfig.h
Index: llvm/tools/llvm-objcopy/CommonConfig.h
===================================================================
--- llvm/tools/llvm-objcopy/CommonConfig.h
+++ llvm/tools/llvm-objcopy/CommonConfig.h
@@ -10,6 +10,7 @@
#define LLVM_TOOLS_LLVM_OBJCOPY_COMMONCONFIG_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
@@ -113,6 +114,11 @@
llvm::function_ref<Error(Error)> ErrorCallback);
bool isPositiveMatch() const { return IsPositiveMatch; }
+ Optional<StringRef> getName() const {
+ if (!R && !G)
+ return Name;
+ return None;
+ }
bool operator==(StringRef S) const {
return R ? R->match(S) : G ? G->match(S) : Name == S;
}
@@ -122,23 +128,32 @@
// Matcher that checks symbol or section names against the command line flags
// provided for that option.
class NameMatcher {
- std::vector<NameOrPattern> PosMatchers;
+ DenseSet<CachedHashStringRef> PosNames;
+ std::vector<NameOrPattern> PosPatterns;
std::vector<NameOrPattern> NegMatchers;
public:
Error addMatcher(Expected<NameOrPattern> Matcher) {
if (!Matcher)
return Matcher.takeError();
- if (Matcher->isPositiveMatch())
- PosMatchers.push_back(std::move(*Matcher));
- else
+ if (Matcher->isPositiveMatch()) {
+ if (Optional<StringRef> MaybeName = Matcher->getName())
+ PosNames.insert(CachedHashStringRef(*MaybeName));
+ else
+ PosPatterns.push_back(std::move(*Matcher));
+ } else {
NegMatchers.push_back(std::move(*Matcher));
+ }
return Error::success();
}
bool matches(StringRef S) const {
- return is_contained(PosMatchers, S) && !is_contained(NegMatchers, S);
+ return (PosNames.contains(CachedHashStringRef(S)) ||
+ is_contained(PosPatterns, S)) &&
+ !is_contained(NegMatchers, S);
+ }
+ bool empty() const {
+ return PosNames.empty() && PosPatterns.empty() && NegMatchers.empty();
}
- bool empty() const { return PosMatchers.empty() && NegMatchers.empty(); }
};
enum class SymbolFlag {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105218.357963.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210712/afe0272d/attachment.bin>
More information about the llvm-commits
mailing list