Skip to content

Commit 61177e6

Browse files
authored
Merge pull request #38176 from etcwilde/ewilde/swift-next/fix-stringref-compare_lower
[Swift Next] Fix `StringRef` API usage
2 parents acb1037 + 1b8b39e commit 61177e6

File tree

13 files changed

+45
-41
lines changed

13 files changed

+45
-41
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ void ASTContext::getVisibleTopLevelModuleNames(
20282028

20292029
// Sort and unique.
20302030
std::sort(names.begin(), names.end(), [](Identifier LHS, Identifier RHS) {
2031-
return LHS.str().compare_lower(RHS.str()) < 0;
2031+
return LHS.str().compare_insensitive(RHS.str()) < 0;
20322032
});
20332033
names.erase(std::unique(names.begin(), names.end()), names.end());
20342034
}

lib/AST/DocComment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool extractParameterOutline(
115115
}
116116

117117
auto HeadingContent = HeadingText->getLiteralContent();
118-
if (!HeadingContent.rtrim().equals_lower("parameters:")) {
118+
if (!HeadingContent.rtrim().equals_insensitive("parameters:")) {
119119
NormalItems.push_back(Child);
120120
continue;
121121
}
@@ -191,7 +191,7 @@ bool extractSeparatedParams(
191191
auto ParagraphContent = ParagraphText->getLiteralContent();
192192
auto PotentialMatch = ParagraphContent.substr(0, ParameterPrefix.size());
193193

194-
if (!PotentialMatch.startswith_lower(ParameterPrefix)) {
194+
if (!PotentialMatch.startswith_insensitive(ParameterPrefix)) {
195195
NormalItems.push_back(Child);
196196
continue;
197197
}

lib/Basic/StringExtras.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ bool swift::canBeMemberName(StringRef identifier) {
4545
}
4646

4747
bool swift::isPreposition(StringRef word) {
48-
#define PREPOSITION(Word) \
49-
if (word.equals_lower(#Word)) \
48+
#define PREPOSITION(Word) \
49+
if (word.equals_insensitive(#Word)) \
5050
return true;
5151
#include "PartsOfSpeech.def"
5252

@@ -55,11 +55,11 @@ bool swift::isPreposition(StringRef word) {
5555

5656
PartOfSpeech swift::getPartOfSpeech(StringRef word) {
5757
// FIXME: This implementation is woefully inefficient.
58-
#define PREPOSITION(Word) \
59-
if (word.equals_lower(#Word)) \
58+
#define PREPOSITION(Word) \
59+
if (word.equals_insensitive(#Word)) \
6060
return PartOfSpeech::Preposition;
61-
#define VERB(Word) \
62-
if (word.equals_lower(#Word)) \
61+
#define VERB(Word) \
62+
if (word.equals_insensitive(#Word)) \
6363
return PartOfSpeech::Verb;
6464
#include "PartsOfSpeech.def"
6565

@@ -392,8 +392,8 @@ static bool matchNameWordToTypeWord(StringRef nameWord, StringRef typeWord) {
392392
// We can match the suffix of the type so long as everything preceding the
393393
// match is neither a lowercase letter nor a '_'. This ignores type
394394
// prefixes for acronyms, e.g., the 'NS' in 'NSURL'.
395-
if (typeWord.endswith_lower(nameWord) &&
396-
!clang::isLowercase(typeWord[typeWord.size()-nameWord.size()])) {
395+
if (typeWord.endswith_insensitive(nameWord) &&
396+
!clang::isLowercase(typeWord[typeWord.size() - nameWord.size()])) {
397397
// Check that everything preceding the match is neither a lowercase letter
398398
// nor a '_'.
399399
for (unsigned i = 0, n = nameWord.size(); i != n; ++i) {
@@ -405,7 +405,7 @@ static bool matchNameWordToTypeWord(StringRef nameWord, StringRef typeWord) {
405405

406406
// We can match a prefix so long as everything following the match is
407407
// a number.
408-
if (typeWord.startswith_lower(nameWord)) {
408+
if (typeWord.startswith_insensitive(nameWord)) {
409409
for (unsigned i = nameWord.size(), n = typeWord.size(); i != n; ++i) {
410410
if (!clang::isDigit(typeWord[i])) return false;
411411
}
@@ -417,7 +417,7 @@ static bool matchNameWordToTypeWord(StringRef nameWord, StringRef typeWord) {
417417
}
418418

419419
// Check for an exact match.
420-
return nameWord.equals_lower(typeWord);
420+
return nameWord.equals_insensitive(typeWord);
421421
}
422422

423423
/// Match the beginning of the name to the given type name.

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,13 +1502,13 @@ void CodeCompletionContext::sortCompletionResults(
15021502
// Sort nameCache, and then transform Results to return the pointers in order.
15031503
std::sort(nameCache.begin(), nameCache.end(),
15041504
[](const ResultAndName &LHS, const ResultAndName &RHS) {
1505-
int Result = StringRef(LHS.name).compare_lower(RHS.name);
1506-
// If the case insensitive comparison is equal, then secondary sort order
1507-
// should be case sensitive.
1508-
if (Result == 0)
1509-
Result = LHS.name.compare(RHS.name);
1510-
return Result < 0;
1511-
});
1505+
int Result = StringRef(LHS.name).compare_insensitive(RHS.name);
1506+
// If the case insensitive comparison is equal, then secondary
1507+
// sort order should be case sensitive.
1508+
if (Result == 0)
1509+
Result = LHS.name.compare(RHS.name);
1510+
return Result < 0;
1511+
});
15121512

15131513
llvm::transform(nameCache, Results.begin(),
15141514
[](const ResultAndName &entry) { return entry.result; });

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ void swift::ide::collectModuleGroups(ModuleDecl *M,
207207
for (auto File : M->getFiles()) {
208208
File->collectAllGroups(Into);
209209
}
210-
std::sort(Into.begin(), Into.end(),
211-
[](StringRef L, StringRef R) { return L.compare_lower(R) < 0; });
210+
std::sort(Into.begin(), Into.end(), [](StringRef L, StringRef R) {
211+
return L.compare_insensitive(R) < 0;
212+
});
212213
}
213214

214215
/// Determine whether the given extension has a Clang node that

lib/IDE/SyntaxModel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ class DocFieldParser {
16241624
;
16251625
StringRef ident(identStart, ptr - identStart);
16261626

1627-
if (ident.equals_lower("parameter")) {
1627+
if (ident.equals_insensitive("parameter")) {
16281628
if (numSpaces > 1 || !advanceIf(' '))
16291629
return None;
16301630
while (advanceIf([](char c) { return c != ':'; }))
@@ -1634,7 +1634,7 @@ class DocFieldParser {
16341634
return ident;
16351635

16361636
} else if (advanceIf(':')) {
1637-
if (ident.equals_lower("parameters") && numSpaces > 1)
1637+
if (ident.equals_insensitive("parameters") && numSpaces > 1)
16381638
return None;
16391639
auto lowerIdent = ident.lower();
16401640
bool isField = llvm::StringSwitch<bool>(lowerIdent)

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T,
12241224
if (quote)
12251225
buffer += '"';
12261226
buffer += library;
1227-
if (!library.endswith_lower(".lib"))
1227+
if (!library.endswith_insensitive(".lib"))
12281228
buffer += ".lib";
12291229
if (quote)
12301230
buffer += '"';

lib/Markup/AST.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ swift::markup::MarkupASTNode *swift::markup::createSimpleField(
341341
if (false) {
342342

343343
}
344-
#define MARKUP_SIMPLE_FIELD(Id, Keyword, XMLKind) \
345-
else if (Tag.compare_lower(#Keyword) == 0) { \
346-
return Id::create(MC, Children); \
344+
#define MARKUP_SIMPLE_FIELD(Id, Keyword, XMLKind) \
345+
else if (Tag.compare_insensitive(#Keyword) == 0) { \
346+
return Id::create(MC, Children); \
347347
}
348348
#include "swift/Markup/SimpleFields.def"
349349
llvm_unreachable("Given tag not for any simple markup field");
@@ -353,9 +353,9 @@ bool swift::markup::isAFieldTag(StringRef Tag) {
353353
if (false) {
354354

355355
}
356-
#define MARKUP_SIMPLE_FIELD(Id, Keyword, XMLKind) \
357-
else if (Tag.compare_lower(#Keyword) == 0) { \
358-
return true; \
356+
#define MARKUP_SIMPLE_FIELD(Id, Keyword, XMLKind) \
357+
else if (Tag.compare_insensitive(#Keyword) == 0) { \
358+
return true; \
359359
}
360360
#include "swift/Markup/SimpleFields.def"
361361
return false;

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ DeclName MissingMemberFailure::findCorrectEnumCaseName(
35523552
auto candidate =
35533553
corrections.getUniqueCandidateMatching([&](ValueDecl *candidate) {
35543554
return (isa<EnumElementDecl>(candidate) &&
3555-
candidate->getBaseIdentifier().str().equals_lower(
3555+
candidate->getBaseIdentifier().str().equals_insensitive(
35563556
memberName.getBaseIdentifier().str()));
35573557
});
35583558
return (candidate ? candidate->getName() : DeclName());

lib/Sema/CSStep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ bool swift::isSIMDOperator(ValueDecl *value) {
756756
if (nominal->getName().empty())
757757
return false;
758758

759-
return nominal->getName().str().startswith_lower("simd");
759+
return nominal->getName().str().startswith_insensitive("simd");
760760
}
761761

762762
bool DisjunctionStep::shortCircuitDisjunctionAt(

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,11 @@ void CodeCompletionOrganizer::Impl::addCompletionsWithFilter(
541541
if (options.fuzzyMatching && filterText.size() >= options.minFuzzyLength) {
542542
match = pattern.matchesCandidate(completion->getName());
543543
} else {
544-
match = completion->getName().startswith_lower(filterText);
544+
match = completion->getName().startswith_insensitive(filterText);
545545
}
546546

547-
bool isExactMatch = match && completion->getName().equals_lower(filterText);
547+
bool isExactMatch =
548+
match && completion->getName().equals_insensitive(filterText);
548549

549550
if (isExactMatch) {
550551
if (!exactMatch) { // first match
@@ -624,7 +625,7 @@ static double combinedScore(const Options &options, double matchScore,
624625

625626
static int compareResultName(Item &a, Item &b) {
626627
// Sort first by filter name (case-insensitive).
627-
if (int primary = StringRef(a.name).compare_lower(b.name))
628+
if (int primary = StringRef(a.name).compare_insensitive(b.name))
628629
return primary;
629630

630631
// Next, sort by full description text.

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ static int printDiags();
302302
static void getSemanticInfo(sourcekitd_variant_t Info, StringRef Filename);
303303

304304
static Optional<int64_t> getReqOptValueAsInt(StringRef Value) {
305-
if (Value.equals_lower("true"))
305+
if (Value.equals_insensitive("true"))
306306
return 1;
307-
if (Value.equals_lower("false"))
307+
if (Value.equals_insensitive("false"))
308308
return 0;
309309
int64_t Ret;
310310
if (Value.find_first_not_of("-0123456789") != StringRef::npos ||

tools/driver/swift_api_digester_main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
196196
bool detectFuncToProperty(SDKNode *R, SDKNode *A) {
197197
if (R->getKind() == SDKNodeKind::DeclFunction) {
198198
if (A->getKind() == SDKNodeKind::DeclVar) {
199-
if (A->getName().compare_lower(R->getName()) == 0) {
199+
if (A->getName().compare_insensitive(R->getName()) == 0) {
200200
R->annotate(NodeAnnotation::GetterToProperty);
201201
} else if (R->getName().startswith("get") &&
202-
R->getName().substr(3).compare_lower(A->getName()) == 0) {
202+
R->getName().substr(3).compare_insensitive(A->getName()) ==
203+
0) {
203204
R->annotate(NodeAnnotation::GetterToProperty);
204205
} else if (R->getName().startswith("set") &&
205-
R->getName().substr(3).compare_lower(A->getName()) == 0) {
206+
R->getName().substr(3).compare_insensitive(A->getName()) ==
207+
0) {
206208
R->annotate(NodeAnnotation::SetterToProperty);
207209
} else {
208210
return false;

0 commit comments

Comments
 (0)