[PATCH] D86406: Speedup llvm-dwarfdump 3.9x
Jan Kratochvil via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 09:36:40 PDT 2020
jankratochvil updated this revision to Diff 287695.
jankratochvil added a comment.
In D86406#2235959 <https://reviews.llvm.org/D86406#2235959>, @joerg wrote:
> Can you change `raw_fd_ostream::has_colors` to memoize the result of `FileDescriptorHasColors(FD)` instead?
Done, yes, that looks simple and it works. The new code is not thread-safe but other member variables there also are not.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86406/new/
https://reviews.llvm.org/D86406
Files:
llvm/include/llvm/Support/raw_ostream.h
llvm/lib/Support/raw_ostream.cpp
Index: llvm/lib/Support/raw_ostream.cpp
===================================================================
--- llvm/lib/Support/raw_ostream.cpp
+++ llvm/lib/Support/raw_ostream.cpp
@@ -857,8 +857,10 @@
return sys::Process::FileDescriptorIsDisplayed(FD);
}
-bool raw_fd_ostream::has_colors() const {
- return sys::Process::FileDescriptorHasColors(FD);
+bool raw_fd_ostream::has_colors() {
+ if (!HasColors)
+ HasColors = sys::Process::FileDescriptorHasColors(FD);
+ return *HasColors;
}
Expected<sys::fs::FileLocker> raw_fd_ostream::lock() {
Index: llvm/include/llvm/Support/raw_ostream.h
===================================================================
--- llvm/include/llvm/Support/raw_ostream.h
+++ llvm/include/llvm/Support/raw_ostream.h
@@ -295,7 +295,7 @@
/// This function determines if this stream is displayed and supports colors.
/// The result is unaffected by calls to enable_color().
- virtual bool has_colors() const { return is_displayed(); }
+ virtual bool has_colors() { return is_displayed(); }
// Enable or disable colors. Once enable_colors(false) is called,
// changeColor() has no effect until enable_colors(true) is called.
@@ -412,6 +412,7 @@
int FD;
bool ShouldClose;
bool SupportsSeeking = false;
+ Optional<bool> HasColors;
#ifdef _WIN32
/// True if this fd refers to a Windows console device. Mintty and other
@@ -479,7 +480,7 @@
bool is_displayed() const override;
- bool has_colors() const override;
+ bool has_colors() override;
std::error_code error() const { return EC; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86406.287695.patch
Type: text/x-patch
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200825/48edd9bd/attachment.bin>
More information about the llvm-commits
mailing list