From 84dc318576e19ef1f86f6b012ba911c4b63f788d Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 27 Mar 2023 18:39:44 -0700 Subject: Don't touch output file if content did not change. (#2738) Co-authored-by: Yong He --- source/core/slang-io.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/core/slang-io.cpp') diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 12cbb9ba8..6f97ef45d 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -993,6 +993,17 @@ namespace Slang return SLANG_OK; } + SlangResult File::writeAllTextIfChanged(const String& fileName, UnownedStringSlice text) + { + String existingContent; + auto result = File::readAllText(fileName, existingContent); + if (SLANG_FAILED(result) || existingContent != text) + { + return File::writeNativeText(fileName, text.begin(), text.getLength()); + } + return SLANG_OK; + } + /* static */SlangResult File::writeNativeText(const String& path, const void* data, size_t size) { FILE* file = fopen(path.getBuffer(), "w"); -- cgit v1.2.3