[PATCH] D100719: [Introspection] Dont emit json if unchanged.
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 18 02:04:15 PDT 2021
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() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100719.338365.patch
Type: text/x-patch
Size: 1286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210418/3dd1e4f7/attachment.bin>
More information about the cfe-commits
mailing list