Remove Set and use unordered_set
This commit is contained in:
parent
7f02ef334f
commit
edef8e4e98
|
@ -4,6 +4,7 @@
|
|||
#include <vector>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "line_and_column.hh"
|
||||
#include "option_manager.hh"
|
||||
|
@ -167,7 +168,7 @@ public:
|
|||
HookManager& hooks() { return m_hooks; }
|
||||
const HookManager& hooks() const { return m_hooks; }
|
||||
|
||||
Set<BufferChangeListener*>& change_listeners() const { return m_change_listeners; }
|
||||
std::unordered_set<BufferChangeListener*>& change_listeners() const { return m_change_listeners; }
|
||||
private:
|
||||
friend class BufferIterator;
|
||||
|
||||
|
@ -211,7 +212,7 @@ private:
|
|||
|
||||
// this is mutable as adding or removing listeners is not muting the
|
||||
// buffer observable state.
|
||||
mutable Set<BufferChangeListener*> m_change_listeners;
|
||||
mutable std::unordered_set<BufferChangeListener*> m_change_listeners;
|
||||
|
||||
OptionManager m_options;
|
||||
HookManager m_hooks;
|
||||
|
|
|
@ -7,19 +7,19 @@ DynamicSelectionList::DynamicSelectionList(const Buffer& buffer,
|
|||
SelectionList selections)
|
||||
: m_buffer(&buffer), SelectionList(std::move(selections))
|
||||
{
|
||||
m_buffer->change_listeners().add(this);
|
||||
m_buffer->change_listeners().insert(this);
|
||||
check_invariant();
|
||||
}
|
||||
|
||||
DynamicSelectionList::~DynamicSelectionList()
|
||||
{
|
||||
m_buffer->change_listeners().remove(this);
|
||||
m_buffer->change_listeners().erase(this);
|
||||
}
|
||||
|
||||
DynamicSelectionList::DynamicSelectionList(const DynamicSelectionList& other)
|
||||
: SelectionList(other), m_buffer(other.m_buffer)
|
||||
{
|
||||
m_buffer->change_listeners().add(this);
|
||||
m_buffer->change_listeners().insert(this);
|
||||
}
|
||||
|
||||
DynamicSelectionList& DynamicSelectionList::operator=(const DynamicSelectionList& other)
|
||||
|
@ -27,9 +27,9 @@ DynamicSelectionList& DynamicSelectionList::operator=(const DynamicSelectionList
|
|||
SelectionList::operator=((const SelectionList&)other);
|
||||
if (m_buffer != other.m_buffer)
|
||||
{
|
||||
m_buffer->change_listeners().remove(this);
|
||||
m_buffer->change_listeners().erase(this);
|
||||
m_buffer = other.m_buffer;
|
||||
m_buffer->change_listeners().add(this);
|
||||
m_buffer->change_listeners().insert(this);
|
||||
}
|
||||
check_invariant();
|
||||
return *this;
|
||||
|
@ -38,7 +38,7 @@ DynamicSelectionList& DynamicSelectionList::operator=(const DynamicSelectionList
|
|||
DynamicSelectionList::DynamicSelectionList(DynamicSelectionList&& other)
|
||||
: SelectionList(std::move(other)), m_buffer(other.m_buffer)
|
||||
{
|
||||
m_buffer->change_listeners().add(this);
|
||||
m_buffer->change_listeners().insert(this);
|
||||
}
|
||||
|
||||
DynamicSelectionList& DynamicSelectionList::operator=(DynamicSelectionList&& other)
|
||||
|
@ -46,9 +46,9 @@ DynamicSelectionList& DynamicSelectionList::operator=(DynamicSelectionList&& oth
|
|||
SelectionList::operator=(std::move(other));
|
||||
if (m_buffer != other.m_buffer)
|
||||
{
|
||||
m_buffer->change_listeners().remove(this);
|
||||
m_buffer->change_listeners().erase(this);
|
||||
m_buffer = other.m_buffer;
|
||||
m_buffer->change_listeners().add(this);
|
||||
m_buffer->change_listeners().insert(this);
|
||||
}
|
||||
check_invariant();
|
||||
return *this;
|
||||
|
|
|
@ -319,10 +319,10 @@ class LastModifiedRangeListener : public BufferChangeListener
|
|||
public:
|
||||
LastModifiedRangeListener(Buffer& buffer)
|
||||
: m_buffer(buffer)
|
||||
{ m_buffer.change_listeners().add(this); }
|
||||
{ m_buffer.change_listeners().insert(this); }
|
||||
|
||||
~LastModifiedRangeListener()
|
||||
{ m_buffer.change_listeners().remove(this); }
|
||||
{ m_buffer.change_listeners().erase(this); }
|
||||
|
||||
void on_insert(const BufferIterator& begin, const BufferIterator& end)
|
||||
{
|
||||
|
|
|
@ -8,23 +8,23 @@ namespace Kakoune
|
|||
FDWatcher::FDWatcher(int fd, Callback callback)
|
||||
: m_fd{fd}, m_callback{std::move(callback)}
|
||||
{
|
||||
EventManager::instance().m_fd_watchers.add(this);
|
||||
EventManager::instance().m_fd_watchers.insert(this);
|
||||
}
|
||||
|
||||
FDWatcher::~FDWatcher()
|
||||
{
|
||||
EventManager::instance().m_fd_watchers.remove(this);
|
||||
EventManager::instance().m_fd_watchers.erase(this);
|
||||
}
|
||||
|
||||
Timer::Timer(TimePoint date, Callback callback)
|
||||
: m_date{date}, m_callback{std::move(callback)}
|
||||
{
|
||||
EventManager::instance().m_timers.add(this);
|
||||
EventManager::instance().m_timers.insert(this);
|
||||
}
|
||||
|
||||
Timer::~Timer()
|
||||
{
|
||||
EventManager::instance().m_timers.remove(this);
|
||||
EventManager::instance().m_timers.erase(this);
|
||||
}
|
||||
|
||||
void Timer::run()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "utils.hh"
|
||||
|
||||
#include <chrono>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
@ -62,8 +63,8 @@ public:
|
|||
private:
|
||||
friend class FDWatcher;
|
||||
friend class Timer;
|
||||
Set<FDWatcher*> m_fd_watchers;
|
||||
Set<Timer*> m_timers;
|
||||
std::unordered_set<FDWatcher*> m_fd_watchers;
|
||||
std::unordered_set<Timer*> m_timers;
|
||||
std::vector<int> m_forced_fd;
|
||||
|
||||
TimePoint m_last;
|
||||
|
|
36
src/utils.hh
36
src/utils.hh
|
@ -207,42 +207,6 @@ const T& clamp(const T& val, const T& min, const T& max)
|
|||
return (val < min ? min : (val > max ? max : val));
|
||||
}
|
||||
|
||||
// *** set ***
|
||||
// generic simple set based on vector
|
||||
|
||||
template<typename T>
|
||||
class Set
|
||||
{
|
||||
public:
|
||||
using iterator = typename std::vector<T>::iterator;
|
||||
using const_iterator = typename std::vector<T>::const_iterator;
|
||||
|
||||
void add(T value)
|
||||
{
|
||||
assert(not contains(m_values, value));
|
||||
m_values.push_back(value);
|
||||
}
|
||||
|
||||
void remove(T value)
|
||||
{
|
||||
auto it = find(m_values, value);
|
||||
assert(it != m_values.end());
|
||||
m_values.erase(it);
|
||||
}
|
||||
|
||||
size_t size() const { return m_values.size(); }
|
||||
bool empty() const { return m_values.empty(); }
|
||||
|
||||
iterator begin() { return m_values.begin(); }
|
||||
iterator end() { return m_values.end(); }
|
||||
|
||||
const_iterator begin() const { return m_values.begin(); }
|
||||
const_iterator end() const { return m_values.end(); }
|
||||
|
||||
private:
|
||||
std::vector<T> m_values;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // utils_hh_INCLUDED
|
||||
|
|
Loading…
Reference in New Issue
Block a user