Skip to content

Commit bd00aba

Browse files
committed
Address comments
1 parent 1f428ce commit bd00aba

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

llvm/include/llvm/MC/StringTableBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class StringTableBuilder {
5757
/// position will be changed if finalize is used. Can only be used before the
5858
/// table is finalized. Priority is only useful with reordering. Strings with
5959
/// same priority will be put together. Strings with higher priority are
60-
/// placed closer to the begin of string table.
60+
/// placed closer to the begin of string table. When adding same string with
61+
/// different priority, the maximum priority win.
6162
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority = 0);
6263
size_t add(StringRef S, uint8_t Priority = 0) {
6364
return add(CachedHashStringRef(S), Priority);

llvm/lib/MC/StringTableBuilder.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,17 @@ void StringTableBuilder::finalizeStringTable(bool Optimize) {
144144
for (StringPair &P : StringIndexMap)
145145
Strings.push_back(&P);
146146

147-
auto getStringPriority = [this](const CachedHashStringRef Str) -> uint8_t {
148-
if (StringPriorityMap.contains(Str))
149-
return StringPriorityMap[Str];
150-
return 0;
151-
};
152-
153147
size_t RangeBegin = 0;
154148
MutableArrayRef<StringPair *> StringsRef(Strings);
155149
if (StringPriorityMap.size()) {
156150
llvm::sort(Strings,
157151
[&](const StringPair *LHS, const StringPair *RHS) -> bool {
158-
return getStringPriority(LHS->first) >
159-
getStringPriority(RHS->first);
152+
return StringPriorityMap.lookup(LHS->first) >
153+
StringPriorityMap.lookup(RHS->first);
160154
});
161-
// Make sure ArrayRef is valid. Although std::sort implementaion is
162-
// normally in-place , it is not guaranteed by standard.
163-
StringsRef = Strings;
164-
165-
uint8_t RangePriority = getStringPriority(Strings[0]->first);
155+
uint8_t RangePriority = StringPriorityMap.lookup(Strings[0]->first);
166156
for (size_t I = 1, E = Strings.size(); I != E && RangePriority; ++I) {
167-
uint8_t Priority = getStringPriority(Strings[I]->first);
157+
uint8_t Priority = StringPriorityMap.lookup(Strings[I]->first);
168158
if (Priority != RangePriority) {
169159
multikeySort(StringsRef.slice(RangeBegin, I - RangeBegin), 0);
170160
RangePriority = Priority;

0 commit comments

Comments
 (0)