diff options
-rw-r--r-- | src/buildtool/build_engine/expression/expression.cpp | 7 | ||||
-rw-r--r-- | src/buildtool/build_engine/expression/expression.hpp | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp index 6ae9bd87..6891d7ab 100644 --- a/src/buildtool/build_engine/expression/expression.cpp +++ b/src/buildtool/build_engine/expression/expression.cpp @@ -114,7 +114,7 @@ auto Expression::ToJson(Expression::JsonMode mode) const -> nlohmann::json { } // NOLINTNEXTLINE(misc-no-recursion) -auto Expression::IsCacheable() const -> bool { +auto Expression::ComputeIsCacheable() const -> bool { // Must be updated whenever we add a new non-cacheable value if (IsName()) { return false; @@ -153,6 +153,11 @@ auto Expression::ToHash() const noexcept -> std::string { } // NOLINTNEXTLINE(misc-no-recursion) +auto Expression::IsCacheable() const -> bool { + return is_cachable_.SetOnceAndGet([this] { return ComputeIsCacheable(); }); +} + +// NOLINTNEXTLINE(misc-no-recursion) auto Expression::FromJson(nlohmann::json const& json) noexcept -> ExpressionPtr { if (json.is_null()) { diff --git a/src/buildtool/build_engine/expression/expression.hpp b/src/buildtool/build_engine/expression/expression.hpp index 047089d2..68dddb10 100644 --- a/src/buildtool/build_engine/expression/expression.hpp +++ b/src/buildtool/build_engine/expression/expression.hpp @@ -242,6 +242,7 @@ class Expression { data_{none_t{}}; AtomicValue<std::string> hash_{}; + AtomicValue<bool> is_cachable_{}; template <class T, std::size_t kIndex = 0> requires(IsValidType<T>()) [[nodiscard]] static consteval auto GetIndexOf() @@ -325,6 +326,7 @@ class Expression { [[nodiscard]] auto TypeStringForIndex() const noexcept -> std::string; [[nodiscard]] auto TypeString() const noexcept -> std::string; [[nodiscard]] auto ComputeHash() const noexcept -> std::string; + [[nodiscard]] auto ComputeIsCacheable() const -> bool; }; namespace std { |