diff options
author | Brad King <brad.king@kitware.com> | 2018-09-24 13:21:29 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-09-24 21:29:15 (GMT) |
commit | 22aa6b67b41808bb9c27aeb0f8f662cd81466843 (patch) | |
tree | b4420c8dad89f0c924b3f0abf6b5da116591e7d0 /Source/cmListFileCache.h | |
parent | 1fe0d72eb6aef12148be0b37d73cf31fbd5f9ca0 (diff) | |
download | CMake-22aa6b67b41808bb9c27aeb0f8f662cd81466843.zip CMake-22aa6b67b41808bb9c27aeb0f8f662cd81466843.tar.gz CMake-22aa6b67b41808bb9c27aeb0f8f662cd81466843.tar.bz2 |
cmListFileCache: Refactor cmListFileBacktrace internals
Replace use of raw pointers and explicit reference counting with
`std::shared_ptr<>`. Use a discriminated union to store either the
bottom level or a call/file context in each heap-allocated entry.
This avoids storing a copy of the bottom in every `cmListFileBacktrace`
instance and shrinks the structure to a single `shared_ptr`.
Diffstat (limited to 'Source/cmListFileCache.h')
-rw-r--r-- | Source/cmListFileCache.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 70f7166..2c91f7a 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <iosfwd> +#include <memory> // IWYU pragma: keep #include <stddef.h> #include <string> #include <vector> @@ -115,18 +116,20 @@ public: // Default-constructed backtrace may not be used until after // set via assignment from a backtrace constructed with a // valid snapshot. - cmListFileBacktrace(); + cmListFileBacktrace() = default; // Construct an empty backtrace whose bottom sits in the directory // indicated by the given valid snapshot. cmListFileBacktrace(cmStateSnapshot const& snapshot); - // Backtraces may be copied and assigned as values. - cmListFileBacktrace(cmListFileBacktrace const& r); - cmListFileBacktrace& operator=(cmListFileBacktrace const& r); - ~cmListFileBacktrace(); + // Backtraces may be copied, moved, and assigned as values. + cmListFileBacktrace(cmListFileBacktrace const&) = default; + cmListFileBacktrace(cmListFileBacktrace&&) noexcept = default; + cmListFileBacktrace& operator=(cmListFileBacktrace const&) = default; + cmListFileBacktrace& operator=(cmListFileBacktrace&&) noexcept = default; + ~cmListFileBacktrace() = default; - cmStateSnapshot GetBottom() const { return this->Bottom; } + cmStateSnapshot GetBottom() const; // Get a backtrace with the given file scope added to the top. // May not be called until after construction with a valid snapshot. @@ -153,14 +156,15 @@ public: // Get the number of 'frames' in this backtrace size_t Depth() const; + // Return true if this backtrace is empty. + bool Empty() const; + private: struct Entry; - - cmStateSnapshot Bottom; - Entry* Cur; - cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* up, + std::shared_ptr<Entry const> TopEntry; + cmListFileBacktrace(std::shared_ptr<Entry const> parent, cmListFileContext const& lfc); - cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* cur); + cmListFileBacktrace(std::shared_ptr<Entry const> top); }; struct cmListFile |