summaryrefslogtreecommitdiff
path: root/Source/cmListFileCache.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-09-24 09:21:29 -0400
committerBrad King <brad.king@kitware.com>2018-09-24 17:29:15 -0400
commit22aa6b67b41808bb9c27aeb0f8f662cd81466843 (patch)
treeb4420c8dad89f0c924b3f0abf6b5da116591e7d0 /Source/cmListFileCache.h
parent1fe0d72eb6aef12148be0b37d73cf31fbd5f9ca0 (diff)
downloadcmake-22aa6b67b41808bb9c27aeb0f8f662cd81466843.tar.gz
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.h26
1 files changed, 15 insertions, 11 deletions
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 70f7166cb0..2c91f7ab09 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