Rename safe_ptr and ref_ptr to SafePtr and RefPtr
This commit is contained in:
parent
6c65c5e080
commit
8df77121d7
|
@ -22,7 +22,7 @@ private:
|
||||||
friend class Scope;
|
friend class Scope;
|
||||||
AliasRegistry() {}
|
AliasRegistry() {}
|
||||||
|
|
||||||
safe_ptr<AliasRegistry> m_parent;
|
SafePtr<AliasRegistry> m_parent;
|
||||||
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
|
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,11 @@ public:
|
||||||
const ByteCoord& coord() const { return m_coord; }
|
const ByteCoord& coord() const { return m_coord; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
safe_ptr<const Buffer> m_buffer;
|
SafePtr<const Buffer> m_buffer;
|
||||||
ByteCoord m_coord;
|
ByteCoord m_coord;
|
||||||
};
|
};
|
||||||
|
|
||||||
using BufferLines = Vector<ref_ptr<StringStorage>, MemoryDomain::BufferContent>;
|
using BufferLines = Vector<RefPtr<StringStorage>, MemoryDomain::BufferContent>;
|
||||||
|
|
||||||
// A Buffer is a in-memory representation of a file
|
// A Buffer is a in-memory representation of a file
|
||||||
//
|
//
|
||||||
|
@ -126,7 +126,7 @@ public:
|
||||||
StringView operator[](LineCount line) const
|
StringView operator[](LineCount line) const
|
||||||
{ return m_lines[line]; }
|
{ return m_lines[line]; }
|
||||||
|
|
||||||
ref_ptr<StringStorage> line_storage(LineCount line) const
|
RefPtr<StringStorage> line_storage(LineCount line) const
|
||||||
{ return m_lines.get_storage(line); }
|
{ return m_lines.get_storage(line); }
|
||||||
|
|
||||||
// returns an iterator at given coordinates. clamp line_and_column
|
// returns an iterator at given coordinates. clamp line_and_column
|
||||||
|
@ -174,11 +174,11 @@ private:
|
||||||
struct LineList : BufferLines
|
struct LineList : BufferLines
|
||||||
{
|
{
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
ref_ptr<StringStorage>& get_storage(LineCount line)
|
RefPtr<StringStorage>& get_storage(LineCount line)
|
||||||
{ return BufferLines::operator[]((int)line); }
|
{ return BufferLines::operator[]((int)line); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
const ref_ptr<StringStorage>& get_storage(LineCount line) const
|
const RefPtr<StringStorage>& get_storage(LineCount line) const
|
||||||
{ return BufferLines::operator[]((int)line); }
|
{ return BufferLines::operator[]((int)line); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Buffer;
|
||||||
class BufferManager : public Singleton<BufferManager>
|
class BufferManager : public Singleton<BufferManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using BufferList = Vector<safe_ptr<Buffer>>;
|
using BufferList = Vector<SafePtr<Buffer>>;
|
||||||
using iterator = BufferList::const_iterator;
|
using iterator = BufferList::const_iterator;
|
||||||
|
|
||||||
~BufferManager();
|
~BufferManager();
|
||||||
|
|
|
@ -138,9 +138,9 @@ private:
|
||||||
|
|
||||||
Flags m_flags;
|
Flags m_flags;
|
||||||
|
|
||||||
safe_ptr<InputHandler> m_input_handler;
|
SafePtr<InputHandler> m_input_handler;
|
||||||
safe_ptr<Window> m_window;
|
SafePtr<Window> m_window;
|
||||||
safe_ptr<Client> m_client;
|
SafePtr<Client> m_client;
|
||||||
|
|
||||||
friend class Client;
|
friend class Client;
|
||||||
Optional<SelectionList> m_selections;
|
Optional<SelectionList> m_selections;
|
||||||
|
@ -170,7 +170,7 @@ struct ScopedEdition
|
||||||
Context& context() const { return m_context; }
|
Context& context() const { return m_context; }
|
||||||
private:
|
private:
|
||||||
Context& m_context;
|
Context& m_context;
|
||||||
safe_ptr<Buffer> m_buffer;
|
SafePtr<Buffer> m_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ void register_env_vars()
|
||||||
"buflist",
|
"buflist",
|
||||||
[](StringView name, const Context& context)
|
[](StringView name, const Context& context)
|
||||||
{ return join(transformed(BufferManager::instance(),
|
{ return join(transformed(BufferManager::instance(),
|
||||||
[](const safe_ptr<Buffer>& b)
|
[](const SafePtr<Buffer>& b)
|
||||||
{ return b->display_name(); }), ':'); }
|
{ return b->display_name(); }), ':'); }
|
||||||
}, {
|
}, {
|
||||||
"timestamp",
|
"timestamp",
|
||||||
|
|
|
@ -5,22 +5,22 @@ namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ref_ptr
|
struct RefPtr
|
||||||
{
|
{
|
||||||
ref_ptr() = default;
|
RefPtr() = default;
|
||||||
ref_ptr(T* ptr) : m_ptr(ptr) { acquire(); }
|
RefPtr(T* ptr) : m_ptr(ptr) { acquire(); }
|
||||||
~ref_ptr() { release(); }
|
~RefPtr() { release(); }
|
||||||
ref_ptr(const ref_ptr& other) : m_ptr(other.m_ptr) { acquire(); }
|
RefPtr(const RefPtr& other) : m_ptr(other.m_ptr) { acquire(); }
|
||||||
ref_ptr(ref_ptr&& other) : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
|
RefPtr(RefPtr&& other) : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
|
||||||
|
|
||||||
ref_ptr& operator=(const ref_ptr& other)
|
RefPtr& operator=(const RefPtr& other)
|
||||||
{
|
{
|
||||||
release();
|
release();
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
acquire();
|
acquire();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
ref_ptr& operator=(ref_ptr&& other)
|
RefPtr& operator=(RefPtr&& other)
|
||||||
{
|
{
|
||||||
release();
|
release();
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
|
@ -35,11 +35,11 @@ struct ref_ptr
|
||||||
|
|
||||||
explicit operator bool() { return m_ptr; }
|
explicit operator bool() { return m_ptr; }
|
||||||
|
|
||||||
friend bool operator==(const ref_ptr& lhs, const ref_ptr& rhs)
|
friend bool operator==(const RefPtr& lhs, const RefPtr& rhs)
|
||||||
{
|
{
|
||||||
return lhs.m_ptr == rhs.m_ptr;
|
return lhs.m_ptr == rhs.m_ptr;
|
||||||
}
|
}
|
||||||
friend bool operator!=(const ref_ptr& lhs, const ref_ptr& rhs)
|
friend bool operator!=(const RefPtr& lhs, const RefPtr& rhs)
|
||||||
{
|
{
|
||||||
return lhs.m_ptr != rhs.m_ptr;
|
return lhs.m_ptr != rhs.m_ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,22 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
// *** safe_ptr: objects that assert nobody references them when they die ***
|
// *** SafePtr: objects that assert nobody references them when they die ***
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class safe_ptr
|
class SafePtr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
safe_ptr() : m_ptr(nullptr) {}
|
SafePtr() : m_ptr(nullptr) {}
|
||||||
explicit safe_ptr(T* ptr) : m_ptr(ptr)
|
explicit SafePtr(T* ptr) : m_ptr(ptr)
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
m_ptr->inc_safe_count(this);
|
m_ptr->inc_safe_count(this);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
safe_ptr(const safe_ptr& other) : safe_ptr(other.m_ptr) {}
|
SafePtr(const SafePtr& other) : SafePtr(other.m_ptr) {}
|
||||||
safe_ptr(safe_ptr&& other) noexcept : m_ptr(other.m_ptr)
|
SafePtr(SafePtr&& other) noexcept : m_ptr(other.m_ptr)
|
||||||
{
|
{
|
||||||
other.m_ptr = nullptr;
|
other.m_ptr = nullptr;
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
m_ptr->safe_ptr_moved(&other, this);
|
m_ptr->safe_ptr_moved(&other, this);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
~safe_ptr()
|
~SafePtr()
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_ptr& operator=(const safe_ptr& other)
|
SafePtr& operator=(const SafePtr& other)
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
if (m_ptr != other.m_ptr)
|
if (m_ptr != other.m_ptr)
|
||||||
|
@ -59,7 +59,7 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_ptr& operator=(safe_ptr&& other) noexcept
|
SafePtr& operator=(SafePtr&& other) noexcept
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
|
@ -74,11 +74,11 @@ public:
|
||||||
|
|
||||||
void reset(T* ptr = nullptr)
|
void reset(T* ptr = nullptr)
|
||||||
{
|
{
|
||||||
*this = safe_ptr(ptr);
|
*this = SafePtr(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; }
|
bool operator== (const SafePtr& other) const { return m_ptr == other.m_ptr; }
|
||||||
bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; }
|
bool operator!= (const SafePtr& other) const { return m_ptr != other.m_ptr; }
|
||||||
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
||||||
bool operator!= (T* ptr) const { return m_ptr != ptr; }
|
bool operator!= (T* ptr) const { return m_ptr != ptr; }
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ private:
|
||||||
size_t m_main = 0;
|
size_t m_main = 0;
|
||||||
Vector<Selection> m_selections;
|
Vector<Selection> m_selections;
|
||||||
|
|
||||||
safe_ptr<Buffer> m_buffer;
|
SafePtr<Buffer> m_buffer;
|
||||||
size_t m_timestamp;
|
size_t m_timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct StringStorage : UseMemoryDomain<MemoryDomain::SharedString>
|
||||||
friend void dec_ref_count(StringStorage* s) { if (--s->refcount == 0) StringStorage::destroy(s); }
|
friend void dec_ref_count(StringStorage* s) { if (--s->refcount == 0) StringStorage::destroy(s); }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline ref_ptr<StringStorage> operator"" _ss(const char* ptr, size_t len)
|
inline RefPtr<StringStorage> operator"" _ss(const char* ptr, size_t len)
|
||||||
{
|
{
|
||||||
return StringStorage::create({ptr, (int)len});
|
return StringStorage::create({ptr, (int)len});
|
||||||
}
|
}
|
||||||
|
@ -75,15 +75,15 @@ public:
|
||||||
return SharedString{StringView::substr(from, length), m_storage};
|
return SharedString{StringView::substr(from, length), m_storage};
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit SharedString(ref_ptr<StringStorage> storage)
|
explicit SharedString(RefPtr<StringStorage> storage)
|
||||||
: StringView{storage->strview()}, m_storage(std::move(storage)) {}
|
: StringView{storage->strview()}, m_storage(std::move(storage)) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SharedString(StringView str, ref_ptr<StringStorage> storage)
|
SharedString(StringView str, RefPtr<StringStorage> storage)
|
||||||
: StringView{str}, m_storage(std::move(storage)) {}
|
: StringView{str}, m_storage(std::move(storage)) {}
|
||||||
|
|
||||||
friend class StringRegistry;
|
friend class StringRegistry;
|
||||||
ref_ptr<StringStorage> m_storage;
|
RefPtr<StringStorage> m_storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline size_t hash_value(const SharedString& str)
|
inline size_t hash_value(const SharedString& str)
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
void purge_unused();
|
void purge_unused();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnorderedMap<StringView, ref_ptr<StringStorage>, MemoryDomain::SharedString> m_strings;
|
UnorderedMap<StringView, RefPtr<StringStorage>, MemoryDomain::SharedString> m_strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline SharedString intern(StringView str)
|
inline SharedString intern(StringView str)
|
||||||
|
|
|
@ -52,7 +52,7 @@ private:
|
||||||
|
|
||||||
void run_hook_in_own_context(const String& hook_name, StringView param);
|
void run_hook_in_own_context(const String& hook_name, StringView param);
|
||||||
|
|
||||||
safe_ptr<Buffer> m_buffer;
|
SafePtr<Buffer> m_buffer;
|
||||||
|
|
||||||
CharCoord m_position;
|
CharCoord m_position;
|
||||||
CharCoord m_dimensions;
|
CharCoord m_dimensions;
|
||||||
|
|
|
@ -50,9 +50,9 @@ private:
|
||||||
int refcount;
|
int refcount;
|
||||||
};
|
};
|
||||||
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
|
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
|
||||||
using Lines = Vector<ref_ptr<StringStorage>, MemoryDomain::WordDB>;
|
using Lines = Vector<RefPtr<StringStorage>, MemoryDomain::WordDB>;
|
||||||
|
|
||||||
safe_ptr<const Buffer> m_buffer;
|
SafePtr<const Buffer> m_buffer;
|
||||||
size_t m_timestamp;
|
size_t m_timestamp;
|
||||||
WordToInfo m_words;
|
WordToInfo m_words;
|
||||||
Lines m_lines;
|
Lines m_lines;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user