From 33e7cd6ff23f6c904314d17c68dc58168fd32d09 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 25 Aug 2024 11:30:49 -0700 Subject: [llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#105943) S.substr(N) is simpler than S.slice(N, StringRef::npos) and S.slice(N, S.size()). Also, substr is probably better recognizable than slice thanks to std::string_view::substr. --- llvm/lib/Object/MachOObjectFile.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Object/MachOObjectFile.cpp') diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index bd9b5dd1..6f3dd4d 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -2436,12 +2436,12 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, a = Name.rfind('/'); if (a == Name.npos || a == 0) goto guess_library; - Foo = Name.slice(a+1, Name.npos); + Foo = Name.substr(a + 1); // Look for a suffix starting with a '_' Idx = Foo.rfind('_'); if (Idx != Foo.npos && Foo.size() >= 2) { - Suffix = Foo.slice(Idx, Foo.npos); + Suffix = Foo.substr(Idx); if (Suffix != "_debug" && Suffix != "_profile") Suffix = StringRef(); else @@ -2468,7 +2468,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, c = Name.rfind('/', b); if (c == Name.npos || c == 0) goto guess_library; - V = Name.slice(c+1, Name.npos); + V = Name.substr(c + 1); if (!V.starts_with("Versions/")) goto guess_library; d = Name.rfind('/', c); @@ -2489,7 +2489,7 @@ guess_library: a = Name.rfind('.'); if (a == Name.npos || a == 0) return StringRef(); - Dylib = Name.slice(a, Name.npos); + Dylib = Name.substr(a); if (Dylib != ".dylib") goto guess_qtx; @@ -2527,7 +2527,7 @@ guess_library: return Lib; guess_qtx: - Qtx = Name.slice(a, Name.npos); + Qtx = Name.substr(a); if (Qtx != ".qtx") return StringRef(); b = Name.rfind('/', a); -- cgit v1.1