njames93 created this revision. njames93 added a reviewer: steveire. njames93 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Saves running the generate inc script in the, somewhat common, case where the json file doesn't need changing. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100719 Files: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp Index: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp =================================================================== --- clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp +++ clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/MemoryBuffer.h" using namespace clang::tooling; using namespace llvm; @@ -105,13 +106,27 @@ JsonObj["classesInClade"] = std::move(ClassesInClade); JsonObj["classEntries"] = std::move(ClassEntries); + llvm::json::Value JsonVal(std::move(JsonObj)); + + bool WriteChange = false; + std::string OutString; + if (auto ExistingOrErr = MemoryBuffer::getFile(JsonPath, /*IsText=*/true)) { + raw_string_ostream Out(OutString); + Out << formatv("{0:2}", JsonVal); + if (ExistingOrErr.get()->getBuffer() == Out.str()) + return; + WriteChange = true; + } + std::error_code EC; llvm::raw_fd_ostream JsonOut(JsonPath, EC, llvm::sys::fs::F_Text); if (EC) return; - llvm::json::Value JsonVal(std::move(JsonObj)); - JsonOut << formatv("{0:2}", JsonVal); + if (WriteChange) + JsonOut << OutString; + else + JsonOut << formatv("{0:2}", JsonVal); } void ASTSrcLocProcessor::generate() {
Index: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp =================================================================== --- clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp +++ clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/MemoryBuffer.h" using namespace clang::tooling; using namespace llvm; @@ -105,13 +106,27 @@ JsonObj["classesInClade"] = std::move(ClassesInClade); JsonObj["classEntries"] = std::move(ClassEntries); + llvm::json::Value JsonVal(std::move(JsonObj)); + + bool WriteChange = false; + std::string OutString; + if (auto ExistingOrErr = MemoryBuffer::getFile(JsonPath, /*IsText=*/true)) { + raw_string_ostream Out(OutString); + Out << formatv("{0:2}", JsonVal); + if (ExistingOrErr.get()->getBuffer() == Out.str()) + return; + WriteChange = true; + } + std::error_code EC; llvm::raw_fd_ostream JsonOut(JsonPath, EC, llvm::sys::fs::F_Text); if (EC) return; - llvm::json::Value JsonVal(std::move(JsonObj)); - JsonOut << formatv("{0:2}", JsonVal); + if (WriteChange) + JsonOut << OutString; + else + JsonOut << formatv("{0:2}", JsonVal); } void ASTSrcLocProcessor::generate() {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits