Skip to content

[llvm] Prefer StringRef::substr to StringRef::slice (NFC) #106190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5784,7 +5784,7 @@ bool AsmParser::parseDirectiveIrpc(SMLoc DirectiveLoc) {
: A[0][0].getString();
for (std::size_t I = 0, End = Values.size(); I != End; ++I) {
MCAsmMacroArgument Arg;
Arg.emplace_back(AsmToken::Identifier, Values.slice(I, I + 1));
Arg.emplace_back(AsmToken::Identifier, Values.substr(I, 1));

// Note that the AtPseudoVariable is enabled for instantiations of .irpc.
// This is undocumented, but GAS seems to support it.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCParser/MasmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7125,7 +7125,7 @@ bool MasmParser::parseDirectiveForc(SMLoc DirectiveLoc, StringRef Directive) {
StringRef Values(Argument);
for (std::size_t I = 0, End = Values.size(); I != End; ++I) {
MCAsmMacroArgument Arg;
Arg.emplace_back(AsmToken::Identifier, Values.slice(I, I + 1));
Arg.emplace_back(AsmToken::Identifier, Values.substr(I, 1));

if (expandMacro(OS, M->Body, Parameter, Arg, M->Locals, getTok().getLoc()))
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,7 @@ ResourceSectionRef::getContents(const coff_resource_data_entry &Entry) {
Expected<StringRef> Contents = S.getContents();
if (!Contents)
return Contents.takeError();
return Contents->slice(Offset, Offset + Entry.DataSize);
return Contents->substr(Offset, Entry.DataSize);
}
}
return createStringError(object_error::parse_failed,
Expand Down
18 changes: 8 additions & 10 deletions llvm/lib/Object/MachOObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ ArrayRef<uint8_t> getSegmentContents(const MachOObjectFile &Obj,
}
auto &Segment = SegmentOrErr.get();
return arrayRefFromStringRef(
Obj.getData().slice(Segment.fileoff, Segment.fileoff + Segment.filesize));
Obj.getData().substr(Segment.fileoff, Segment.filesize));
}
} // namespace

Expand Down Expand Up @@ -2454,9 +2454,8 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name,
Idx = 0;
else
Idx = b+1;
F = Name.slice(Idx, Idx + Foo.size());
DotFramework = Name.slice(Idx + Foo.size(),
Idx + Foo.size() + sizeof(".framework/")-1);
F = Name.substr(Idx, Foo.size());
DotFramework = Name.substr(Idx + Foo.size(), sizeof(".framework/") - 1);
if (F == Foo && DotFramework == ".framework/") {
isFramework = true;
return Foo;
Expand All @@ -2476,9 +2475,8 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name,
Idx = 0;
else
Idx = d+1;
F = Name.slice(Idx, Idx + Foo.size());
DotFramework = Name.slice(Idx + Foo.size(),
Idx + Foo.size() + sizeof(".framework/")-1);
F = Name.substr(Idx, Foo.size());
DotFramework = Name.substr(Idx + Foo.size(), sizeof(".framework/") - 1);
if (F == Foo && DotFramework == ".framework/") {
isFramework = true;
return Foo;
Expand All @@ -2495,7 +2493,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name,

// First pull off the version letter for the form Foo.A.dylib if any.
if (a >= 3) {
Dot = Name.slice(a-2, a-1);
Dot = Name.substr(a - 2, 1);
if (Dot == ".")
a = a - 2;
}
Expand All @@ -2520,7 +2518,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name,
// There are incorrect library names of the form:
// libATS.A_profile.dylib so check for these.
if (Lib.size() >= 3) {
Dot = Lib.slice(Lib.size()-2, Lib.size()-1);
Dot = Lib.substr(Lib.size() - 2, 1);
if (Dot == ".")
Lib = Lib.slice(0, Lib.size()-2);
}
Expand All @@ -2537,7 +2535,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name,
Lib = Name.slice(b+1, a);
// There are library names of the form: QT.A.qtx so check for these.
if (Lib.size() >= 3) {
Dot = Lib.slice(Lib.size()-2, Lib.size()-1);
Dot = Lib.substr(Lib.size() - 2, 1);
if (Dot == ".")
Lib = Lib.slice(0, Lib.size()-2);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
if (DotOffset != StringRef::npos) {
consumeToken();
StringRef LHS = Identifier.slice(0, DotOffset);
StringRef Dot = Identifier.slice(DotOffset, DotOffset + 1);
StringRef Dot = Identifier.substr(DotOffset, 1);
StringRef RHS = Identifier.substr(DotOffset + 1);
if (!RHS.empty()) {
getLexer().UnLex(AsmToken(AsmToken::Identifier, RHS));
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ void MatchableInfo::tokenizeAsmString(const AsmMatcherInfo &Info,
InTok = false;
IsIsolatedToken = false;
}
addAsmOperand(String.slice(i, i + 1), IsIsolatedToken);
addAsmOperand(String.substr(i, 1), IsIsolatedToken);
Prev = i + 1;
IsIsolatedToken = true;
continue;
Expand All @@ -1037,7 +1037,7 @@ void MatchableInfo::tokenizeAsmString(const AsmMatcherInfo &Info,
}
++i;
assert(i != String.size() && "Invalid quoted character");
addAsmOperand(String.slice(i, i + 1), IsIsolatedToken);
addAsmOperand(String.substr(i, 1), IsIsolatedToken);
Prev = i + 1;
IsIsolatedToken = false;
break;
Expand Down
Loading