mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-24 20:13:00 +03:00
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;
|
||||
AliasRegistry() {}
|
||||
|
||||
safe_ptr<AliasRegistry> m_parent;
|
||||
SafePtr<AliasRegistry> m_parent;
|
||||
UnorderedMap<String, String, MemoryDomain::Aliases> m_aliases;
|
||||
};
|
||||
|
||||
|
@ -55,11 +55,11 @@ public:
|
||||
const ByteCoord& coord() const { return m_coord; }
|
||||
|
||||
private:
|
||||
safe_ptr<const Buffer> m_buffer;
|
||||
SafePtr<const Buffer> m_buffer;
|
||||
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
|
||||
//
|
||||
@ -126,7 +126,7 @@ public:
|
||||
StringView operator[](LineCount line) const
|
||||
{ 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); }
|
||||
|
||||
// returns an iterator at given coordinates. clamp line_and_column
|
||||
@ -174,11 +174,11 @@ private:
|
||||
struct LineList : BufferLines
|
||||
{
|
||||
[[gnu::always_inline]]
|
||||
ref_ptr<StringStorage>& get_storage(LineCount line)
|
||||
RefPtr<StringStorage>& get_storage(LineCount line)
|
||||
{ return BufferLines::operator[]((int)line); }
|
||||
|
||||
[[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); }
|
||||
|
||||
[[gnu::always_inline]]
|
||||
|
@ -13,7 +13,7 @@ class Buffer;
|
||||
class BufferManager : public Singleton<BufferManager>
|
||||
{
|
||||
public:
|
||||
using BufferList = Vector<safe_ptr<Buffer>>;
|
||||
using BufferList = Vector<SafePtr<Buffer>>;
|
||||
using iterator = BufferList::const_iterator;
|
||||
|
||||
~BufferManager();
|
||||
|
@ -138,9 +138,9 @@ private:
|
||||
|
||||
Flags m_flags;
|
||||
|
||||
safe_ptr<InputHandler> m_input_handler;
|
||||
safe_ptr<Window> m_window;
|
||||
safe_ptr<Client> m_client;
|
||||
SafePtr<InputHandler> m_input_handler;
|
||||
SafePtr<Window> m_window;
|
||||
SafePtr<Client> m_client;
|
||||
|
||||
friend class Client;
|
||||
Optional<SelectionList> m_selections;
|
||||
@ -170,7 +170,7 @@ struct ScopedEdition
|
||||
Context& context() const { return m_context; }
|
||||
private:
|
||||
Context& m_context;
|
||||
safe_ptr<Buffer> m_buffer;
|
||||
SafePtr<Buffer> m_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ void register_env_vars()
|
||||
"buflist",
|
||||
[](StringView name, const Context& context)
|
||||
{ return join(transformed(BufferManager::instance(),
|
||||
[](const safe_ptr<Buffer>& b)
|
||||
[](const SafePtr<Buffer>& b)
|
||||
{ return b->display_name(); }), ':'); }
|
||||
}, {
|
||||
"timestamp",
|
||||
|
@ -5,22 +5,22 @@ namespace Kakoune
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct ref_ptr
|
||||
struct RefPtr
|
||||
{
|
||||
ref_ptr() = default;
|
||||
ref_ptr(T* ptr) : m_ptr(ptr) { acquire(); }
|
||||
~ref_ptr() { release(); }
|
||||
ref_ptr(const ref_ptr& other) : m_ptr(other.m_ptr) { acquire(); }
|
||||
ref_ptr(ref_ptr&& other) : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
|
||||
RefPtr() = default;
|
||||
RefPtr(T* ptr) : m_ptr(ptr) { acquire(); }
|
||||
~RefPtr() { release(); }
|
||||
RefPtr(const RefPtr& other) : m_ptr(other.m_ptr) { acquire(); }
|
||||
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();
|
||||
m_ptr = other.m_ptr;
|
||||
acquire();
|
||||
return *this;
|
||||
}
|
||||
ref_ptr& operator=(ref_ptr&& other)
|
||||
RefPtr& operator=(RefPtr&& other)
|
||||
{
|
||||
release();
|
||||
m_ptr = other.m_ptr;
|
||||
@ -35,11 +35,11 @@ struct ref_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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -13,22 +13,22 @@
|
||||
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>
|
||||
class safe_ptr
|
||||
class SafePtr
|
||||
{
|
||||
public:
|
||||
safe_ptr() : m_ptr(nullptr) {}
|
||||
explicit safe_ptr(T* ptr) : m_ptr(ptr)
|
||||
SafePtr() : m_ptr(nullptr) {}
|
||||
explicit SafePtr(T* ptr) : m_ptr(ptr)
|
||||
{
|
||||
#ifdef KAK_DEBUG
|
||||
if (m_ptr)
|
||||
m_ptr->inc_safe_count(this);
|
||||
#endif
|
||||
}
|
||||
safe_ptr(const safe_ptr& other) : safe_ptr(other.m_ptr) {}
|
||||
safe_ptr(safe_ptr&& other) noexcept : m_ptr(other.m_ptr)
|
||||
SafePtr(const SafePtr& other) : SafePtr(other.m_ptr) {}
|
||||
SafePtr(SafePtr&& other) noexcept : m_ptr(other.m_ptr)
|
||||
{
|
||||
other.m_ptr = nullptr;
|
||||
#ifdef KAK_DEBUG
|
||||
@ -36,7 +36,7 @@ public:
|
||||
m_ptr->safe_ptr_moved(&other, this);
|
||||
#endif
|
||||
}
|
||||
~safe_ptr()
|
||||
~SafePtr()
|
||||
{
|
||||
#ifdef KAK_DEBUG
|
||||
if (m_ptr)
|
||||
@ -44,7 +44,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
safe_ptr& operator=(const safe_ptr& other)
|
||||
SafePtr& operator=(const SafePtr& other)
|
||||
{
|
||||
#ifdef KAK_DEBUG
|
||||
if (m_ptr != other.m_ptr)
|
||||
@ -59,7 +59,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
safe_ptr& operator=(safe_ptr&& other) noexcept
|
||||
SafePtr& operator=(SafePtr&& other) noexcept
|
||||
{
|
||||
#ifdef KAK_DEBUG
|
||||
if (m_ptr)
|
||||
@ -74,11 +74,11 @@ public:
|
||||
|
||||
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 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 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; }
|
||||
|
||||
|
@ -136,7 +136,7 @@ private:
|
||||
size_t m_main = 0;
|
||||
Vector<Selection> m_selections;
|
||||
|
||||
safe_ptr<Buffer> m_buffer;
|
||||
SafePtr<Buffer> m_buffer;
|
||||
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); }
|
||||
};
|
||||
|
||||
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});
|
||||
}
|
||||
@ -75,15 +75,15 @@ public:
|
||||
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)) {}
|
||||
|
||||
private:
|
||||
SharedString(StringView str, ref_ptr<StringStorage> storage)
|
||||
SharedString(StringView str, RefPtr<StringStorage> storage)
|
||||
: StringView{str}, m_storage(std::move(storage)) {}
|
||||
|
||||
friend class StringRegistry;
|
||||
ref_ptr<StringStorage> m_storage;
|
||||
RefPtr<StringStorage> m_storage;
|
||||
};
|
||||
|
||||
inline size_t hash_value(const SharedString& str)
|
||||
@ -99,7 +99,7 @@ public:
|
||||
void purge_unused();
|
||||
|
||||
private:
|
||||
UnorderedMap<StringView, ref_ptr<StringStorage>, MemoryDomain::SharedString> m_strings;
|
||||
UnorderedMap<StringView, RefPtr<StringStorage>, MemoryDomain::SharedString> m_strings;
|
||||
};
|
||||
|
||||
inline SharedString intern(StringView str)
|
||||
|
@ -52,7 +52,7 @@ private:
|
||||
|
||||
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_dimensions;
|
||||
|
@ -50,9 +50,9 @@ private:
|
||||
int refcount;
|
||||
};
|
||||
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;
|
||||
WordToInfo m_words;
|
||||
Lines m_lines;
|
||||
|
Loading…
Reference in New Issue
Block a user