Avoid extra indirection for storing FifoWatcher

By improving the Value interface we can avoid storing a unique_ptr
to a FifoWatcher and directly store the FifoWatcher.
This commit is contained in:
Maxime Coste 2023-02-10 12:56:32 +11:00
parent eb0e983133
commit 3150e9b3cd
2 changed files with 7 additions and 2 deletions

View File

@ -264,7 +264,7 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll
bool m_scroll; bool m_scroll;
}; };
buffer->values()[fifo_watcher_id] = Value(std::make_unique<FifoWatcher>(fd, *buffer, scroll)); buffer->values()[fifo_watcher_id] = Value(Meta::Type<FifoWatcher>{}, fd, *buffer, scroll);
buffer->flags() = flags | Buffer::Flags::Fifo | Buffer::Flags::NoUndo; buffer->flags() = flags | Buffer::Flags::Fifo | Buffer::Flags::NoUndo;
buffer->run_hook_in_own_context(Hook::BufOpenFifo, buffer->name()); buffer->run_hook_in_own_context(Hook::BufOpenFifo, buffer->name());

View File

@ -3,6 +3,7 @@
#include "hash_map.hh" #include "hash_map.hh"
#include "units.hh" #include "units.hh"
#include "meta.hh"
#include <type_traits> #include <type_traits>
#include <memory> #include <memory>
@ -20,6 +21,10 @@ struct Value
Value(T&& val) Value(T&& val)
: m_value{new Model<std::remove_cvref_t<T>>{std::forward<T>(val)}} {} : m_value{new Model<std::remove_cvref_t<T>>{std::forward<T>(val)}} {}
template<typename T>
Value(Meta::Type<T>, auto&&... args) :
m_value(new Model<T>(std::forward<decltype(args)>(args)...)) {}
Value(const Value& val) = delete; Value(const Value& val) = delete;
Value(Value&&) = default; Value(Value&&) = default;
@ -58,7 +63,7 @@ private:
template<typename T> template<typename T>
struct Model : public Concept, public UseMemoryDomain<MemoryDomain::Values> struct Model : public Concept, public UseMemoryDomain<MemoryDomain::Values>
{ {
Model(T&& val) : m_content(std::move(val)) {} Model(auto&&... args) : m_content(std::forward<decltype(args)>(args)...) {}
const std::type_info& type() const override { return typeid(T); } const std::type_info& type() const override { return typeid(T); }
T m_content; T m_content;