From: Rafael Espindola Date: Fri, 1 Aug 2014 14:11:14 +0000 (+0000) Subject: Simplify the code a bit with std::unique_ptr. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=19f5c7eba61c179a0981cc752d9ef631d2853d89;p=oota-llvm.git Simplify the code a bit with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214514 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 9245e1143ad..9cd1fe75760 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -631,7 +631,7 @@ struct CheckString { /// /// \param PreserveHorizontal Don't squash consecutive horizontal whitespace /// characters to a single space. -static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB, +static MemoryBuffer *CanonicalizeInputFile(std::unique_ptr MB, bool PreserveHorizontal) { SmallString<128> NewFile; NewFile.reserve(MB->getBufferSize()); @@ -657,12 +657,8 @@ static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB, ++Ptr; } - // Free the old buffer and return a new one. - MemoryBuffer *MB2 = - MemoryBuffer::getMemBufferCopy(NewFile.str(), MB->getBufferIdentifier()); - - delete MB; - return MB2; + return MemoryBuffer::getMemBufferCopy(NewFile.str(), + MB->getBufferIdentifier()); } static bool IsPartOfWord(char c) { @@ -837,7 +833,7 @@ static bool ReadCheckFile(SourceMgr &SM, // If we want to canonicalize whitespace, strip excess whitespace from the // buffer containing the CHECK lines. Remove DOS style line endings. - MemoryBuffer *F = CanonicalizeInputFile(FileOrErr.get().release(), + MemoryBuffer *F = CanonicalizeInputFile(std::move(FileOrErr.get()), NoCanonicalizeWhiteSpace); SM.AddNewSourceBuffer(F, SMLoc()); @@ -1272,7 +1268,7 @@ int main(int argc, char **argv) { // Remove duplicate spaces in the input file if requested. // Remove DOS style line endings. MemoryBuffer *F = - CanonicalizeInputFile(File.release(), NoCanonicalizeWhiteSpace); + CanonicalizeInputFile(std::move(File), NoCanonicalizeWhiteSpace); SM.AddNewSourceBuffer(F, SMLoc());