Skip to content

Commit 22e55ba

Browse files
[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#106330)
S.substr(N) is simpler than S.slice(N, StringRef::npos). Also, substr is probably better recognizable than slice thanks to std::string_view::substr.
1 parent 6332c36 commit 22e55ba

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ Pattern::parseVariable(StringRef &Str, const SourceMgr &SM) {
298298
++I;
299299

300300
if (I == Str.size())
301-
return ErrorDiagnostic::get(SM, Str.slice(I, StringRef::npos),
301+
return ErrorDiagnostic::get(SM, Str.substr(I),
302302
StringRef("empty ") +
303303
(IsPseudo ? "pseudo " : "global ") +
304304
"variable name");

llvm/tools/llvm-objcopy/ObjcopyOptions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ static Expected<int64_t> parseChangeSectionLMA(StringRef ArgValue,
556556
StringRef OptionName) {
557557
StringRef StringValue;
558558
if (ArgValue.starts_with("*+")) {
559-
StringValue = ArgValue.slice(2, StringRef::npos);
559+
StringValue = ArgValue.substr(2);
560560
} else if (ArgValue.starts_with("*-")) {
561-
StringValue = ArgValue.slice(1, StringRef::npos);
561+
StringValue = ArgValue.substr(1);
562562
} else if (ArgValue.contains("=")) {
563563
return createStringError(errc::invalid_argument,
564564
"bad format for " + OptionName +
@@ -608,7 +608,7 @@ parseChangeSectionAddr(StringRef ArgValue, StringRef OptionName,
608608
SectionPattern, SectionMatchStyle, ErrorCallback)))
609609
return std::move(E);
610610

611-
StringRef Value = ArgValue.slice(LastSymbolIndex + 1, StringRef::npos);
611+
StringRef Value = ArgValue.substr(LastSymbolIndex + 1);
612612
if (Value.empty()) {
613613
switch (UpdateSymbol) {
614614
case '+':

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ class VFSFromYAMLTest : public ::testing::Test {
15831583
IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem(),
15841584
StringRef YAMLFilePath = "") {
15851585
std::string VersionPlusContent("{\n 'version':0,\n");
1586-
VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
1586+
VersionPlusContent += Content.substr(Content.find('{') + 1);
15871587
return getFromYAMLRawString(VersionPlusContent, ExternalFS, YAMLFilePath);
15881588
}
15891589

0 commit comments

Comments
 (0)