From aaec1338b1a504ea92fcc5c4297e5b942b56ea10 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Fri, 4 May 2012 15:32:05 +0000 Subject: [PATCH] StringRefize code because we're good even when we crash. Patch by Jordy Rose. llvm-svn: 156172 --- clang/lib/Driver/Driver.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3e7a5a23de2b..872be32b79b8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -528,12 +528,12 @@ void Driver::generateCompilationDiagnostics(Compilation &C, I += 16; E = Cmd.find(" ", I); assert (E != std::string::npos && "-main-file-name missing argument?"); - std::string OldFilename = Cmd.substr(I, E - I); - std::string NewFilename = llvm::sys::path::filename(*it).str(); - I = Cmd.rfind(OldFilename); - E = I + OldFilename.length() - 1; - I = Cmd.rfind(" ", I); - Cmd.replace(I + 1, E - I, NewFilename); + StringRef OldFilename = StringRef(Cmd).slice(I, E); + StringRef NewFilename = llvm::sys::path::filename(*it); + I = StringRef(Cmd).rfind(OldFilename); + E = I + OldFilename.size(); + I = Cmd.rfind(" ", I) + 1; + Cmd.replace(I, E - I, NewFilename.data(), NewFilename.size()); ScriptOS << Cmd; Diag(clang::diag::note_drv_command_failed_diag_msg) << Script; }