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/Support/VirtualFileSystem.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Support/VirtualFileSystem.cpp') diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 9d21eba..6d756f4 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2780,7 +2780,7 @@ bool JSONWriter::containedIn(StringRef Parent, StringRef Path) { StringRef JSONWriter::containedPart(StringRef Parent, StringRef Path) { assert(!Parent.empty()); assert(containedIn(Parent, Path)); - return Path.slice(Parent.size() + 1, StringRef::npos); + return Path.substr(Parent.size() + 1); } void JSONWriter::startDirectory(StringRef Path) { @@ -2846,7 +2846,7 @@ void JSONWriter::write(ArrayRef Entries, if (UseOverlayRelative) { assert(RPath.starts_with(OverlayDir) && "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDir.size(), RPath.size()); + RPath = RPath.substr(OverlayDir.size()); } bool IsCurrentDirEmpty = true; @@ -2879,7 +2879,7 @@ void JSONWriter::write(ArrayRef Entries, if (UseOverlayRelative) { assert(RPath.starts_with(OverlayDir) && "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDir.size(), RPath.size()); + RPath = RPath.substr(OverlayDir.size()); } if (!Entry.IsDirectory) { writeEntry(path::filename(Entry.VPath), RPath); -- cgit v1.1