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:
parent
eb0e983133
commit
3150e9b3cd
|
@ -264,7 +264,7 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool 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->run_hook_in_own_context(Hook::BufOpenFifo, buffer->name());
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "hash_map.hh"
|
||||
#include "units.hh"
|
||||
#include "meta.hh"
|
||||
|
||||
#include <type_traits>
|
||||
#include <memory>
|
||||
|
@ -20,6 +21,10 @@ struct Value
|
|||
Value(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(Value&&) = default;
|
||||
|
||||
|
@ -58,7 +63,7 @@ private:
|
|||
template<typename T>
|
||||
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); }
|
||||
|
||||
T m_content;
|
||||
|
|
Loading…
Reference in New Issue
Block a user