diff --git a/include/toml11/impl/syntax_impl.hpp b/include/toml11/impl/syntax_impl.hpp index fdd04a3..2dc768a 100644 --- a/include/toml11/impl/syntax_impl.hpp +++ b/include/toml11/impl/syntax_impl.hpp @@ -21,27 +21,21 @@ struct syntax_cache static_assert(std::is_base_of::value, ""); explicit syntax_cache(F f) - : func_(std::move(f)), cache_{} + : func_(std::move(f)), cache_(cxx::make_nullopt()) {} value_type const& at(const spec& s) { - const auto found = std::find_if(cache_.begin(), cache_.end(), - [&s](const std::pair& kv) { return kv.first == s; }); - if(found == cache_.end()) + if( ! this->cache_.has_value() || this->cache_.value().first != s) { - this->cache_.emplace_back(s, func_(s)); - return cache_.back().second; - } - else - { - return found->second; + this->cache_ = std::make_pair(s, func_(s)); } + return this->cache_.value().second; } private: F func_; - std::vector> cache_; + cxx::optional> cache_; }; template