#pragma once #include "Value/value.hpp" #include #include #include #include #include namespace Fig { class IntPool { private: static constexpr ValueType::IntClass CACHE_MIN = -128; static constexpr ValueType::IntClass CACHE_MAX = 127; std::array cache; public: IntPool() { for (ValueType::IntClass i = CACHE_MIN; i <= CACHE_MAX; ++i) { cache[i - CACHE_MIN] = std::make_shared(i); } } ObjectPtr createInt(ValueType::IntClass val) const { if (val >= CACHE_MIN && val <= CACHE_MAX) { return cache[val - CACHE_MIN]; } return std::make_shared(val); } static const IntPool &getInstance() { static IntPool pool; return pool; } }; }; // namespace Fig