From 71dc046d3ca780cf946bb557fefc45e3f26c3b80 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 3 Oct 2014 18:52:54 +0000 Subject: [PATCH] ASTUnit: Replace out parameter with return value, we have NRVO for this. And elide the copy when pushing the return value into a vector. NFC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219001 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/ASTUnit.cpp | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 963752a83f..f7b9b71b46 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1277,42 +1277,44 @@ makeStandaloneRange(CharSourceRange Range, const SourceManager &SM, return std::make_pair(Offset, EndOffset); } -static void makeStandaloneFixIt(const SourceManager &SM, - const LangOptions &LangOpts, - const FixItHint &InFix, - ASTUnit::StandaloneFixIt &OutFix) { +static ASTUnit::StandaloneFixIt makeStandaloneFixIt(const SourceManager &SM, + const LangOptions &LangOpts, + const FixItHint &InFix) { + ASTUnit::StandaloneFixIt OutFix; OutFix.RemoveRange = makeStandaloneRange(InFix.RemoveRange, SM, LangOpts); OutFix.InsertFromRange = makeStandaloneRange(InFix.InsertFromRange, SM, LangOpts); OutFix.CodeToInsert = InFix.CodeToInsert; OutFix.BeforePreviousInsertions = InFix.BeforePreviousInsertions; + return OutFix; } -static void makeStandaloneDiagnostic(const LangOptions &LangOpts, - const StoredDiagnostic &InDiag, - ASTUnit::StandaloneDiagnostic &OutDiag) { +static ASTUnit::StandaloneDiagnostic +makeStandaloneDiagnostic(const LangOptions &LangOpts, + const StoredDiagnostic &InDiag) { + ASTUnit::StandaloneDiagnostic OutDiag; OutDiag.ID = InDiag.getID(); OutDiag.Level = InDiag.getLevel(); OutDiag.Message = InDiag.getMessage(); OutDiag.LocOffset = 0; if (InDiag.getLocation().isInvalid()) - return; + return OutDiag; const SourceManager &SM = InDiag.getLocation().getManager(); SourceLocation FileLoc = SM.getFileLoc(InDiag.getLocation()); OutDiag.Filename = SM.getFilename(FileLoc); if (OutDiag.Filename.empty()) - return; + return OutDiag; OutDiag.LocOffset = SM.getFileOffset(FileLoc); for (StoredDiagnostic::range_iterator I = InDiag.range_begin(), E = InDiag.range_end(); I != E; ++I) { OutDiag.Ranges.push_back(makeStandaloneRange(*I, SM, LangOpts)); } - for (StoredDiagnostic::fixit_iterator - I = InDiag.fixit_begin(), E = InDiag.fixit_end(); I != E; ++I) { - ASTUnit::StandaloneFixIt Fix; - makeStandaloneFixIt(SM, LangOpts, *I, Fix); - OutDiag.FixIts.push_back(Fix); - } + for (StoredDiagnostic::fixit_iterator I = InDiag.fixit_begin(), + E = InDiag.fixit_end(); + I != E; ++I) + OutDiag.FixIts.push_back(makeStandaloneFixIt(SM, LangOpts, *I)); + + return OutDiag; } /// \brief Attempt to build or re-use a precompiled preamble when (re-)parsing @@ -1574,13 +1576,11 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( // Transfer any diagnostics generated when parsing the preamble into the set // of preamble diagnostics. - for (stored_diag_iterator - I = stored_diag_afterDriver_begin(), - E = stored_diag_end(); I != E; ++I) { - StandaloneDiagnostic Diag; - makeStandaloneDiagnostic(Clang->getLangOpts(), *I, Diag); - PreambleDiagnostics.push_back(Diag); - } + for (stored_diag_iterator I = stored_diag_afterDriver_begin(), + E = stored_diag_end(); + I != E; ++I) + PreambleDiagnostics.push_back( + makeStandaloneDiagnostic(Clang->getLangOpts(), *I)); Act->EndSourceFile(); -- 2.40.0