diff --git a/src/alias_registry.hh b/src/alias_registry.hh index f29ee9e6c..4f1a472b7 100644 --- a/src/alias_registry.hh +++ b/src/alias_registry.hh @@ -22,7 +22,7 @@ private: friend class Scope; AliasRegistry() {} - safe_ptr m_parent; + SafePtr m_parent; UnorderedMap m_aliases; }; diff --git a/src/buffer.hh b/src/buffer.hh index c3a5dcb23..4c4a6ac54 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -55,11 +55,11 @@ public: const ByteCoord& coord() const { return m_coord; } private: - safe_ptr m_buffer; + SafePtr m_buffer; ByteCoord m_coord; }; -using BufferLines = Vector, MemoryDomain::BufferContent>; +using BufferLines = Vector, 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 line_storage(LineCount line) const + RefPtr 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& get_storage(LineCount line) + RefPtr& get_storage(LineCount line) { return BufferLines::operator[]((int)line); } [[gnu::always_inline]] - const ref_ptr& get_storage(LineCount line) const + const RefPtr& get_storage(LineCount line) const { return BufferLines::operator[]((int)line); } [[gnu::always_inline]] diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index 8a046ff39..8dab6df7c 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -13,7 +13,7 @@ class Buffer; class BufferManager : public Singleton { public: - using BufferList = Vector>; + using BufferList = Vector>; using iterator = BufferList::const_iterator; ~BufferManager(); diff --git a/src/context.hh b/src/context.hh index bd89be27d..833239944 100644 --- a/src/context.hh +++ b/src/context.hh @@ -138,9 +138,9 @@ private: Flags m_flags; - safe_ptr m_input_handler; - safe_ptr m_window; - safe_ptr m_client; + SafePtr m_input_handler; + SafePtr m_window; + SafePtr m_client; friend class Client; Optional m_selections; @@ -170,7 +170,7 @@ struct ScopedEdition Context& context() const { return m_context; } private: Context& m_context; - safe_ptr m_buffer; + SafePtr m_buffer; }; } diff --git a/src/main.cc b/src/main.cc index 0d7172bec..7f83f802e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -60,7 +60,7 @@ void register_env_vars() "buflist", [](StringView name, const Context& context) { return join(transformed(BufferManager::instance(), - [](const safe_ptr& b) + [](const SafePtr& b) { return b->display_name(); }), ':'); } }, { "timestamp", diff --git a/src/ref_ptr.hh b/src/ref_ptr.hh index 7bd2ed83e..09ec1f48d 100644 --- a/src/ref_ptr.hh +++ b/src/ref_ptr.hh @@ -5,22 +5,22 @@ namespace Kakoune { template -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; } diff --git a/src/safe_ptr.hh b/src/safe_ptr.hh index 2f9e4ca5e..6366bd132 100644 --- a/src/safe_ptr.hh +++ b/src/safe_ptr.hh @@ -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 -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; } diff --git a/src/selection.hh b/src/selection.hh index cc435aed4..1a5834a9e 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -136,7 +136,7 @@ private: size_t m_main = 0; Vector m_selections; - safe_ptr m_buffer; + SafePtr m_buffer; size_t m_timestamp; }; diff --git a/src/shared_string.hh b/src/shared_string.hh index f9adf7371..a73f8dd2c 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -44,7 +44,7 @@ struct StringStorage : UseMemoryDomain friend void dec_ref_count(StringStorage* s) { if (--s->refcount == 0) StringStorage::destroy(s); } }; -inline ref_ptr operator"" _ss(const char* ptr, size_t len) +inline RefPtr 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 storage) + explicit SharedString(RefPtr storage) : StringView{storage->strview()}, m_storage(std::move(storage)) {} private: - SharedString(StringView str, ref_ptr storage) + SharedString(StringView str, RefPtr storage) : StringView{str}, m_storage(std::move(storage)) {} friend class StringRegistry; - ref_ptr m_storage; + RefPtr m_storage; }; inline size_t hash_value(const SharedString& str) @@ -99,7 +99,7 @@ public: void purge_unused(); private: - UnorderedMap, MemoryDomain::SharedString> m_strings; + UnorderedMap, MemoryDomain::SharedString> m_strings; }; inline SharedString intern(StringView str) diff --git a/src/window.hh b/src/window.hh index aaeb34a67..ad04396d6 100644 --- a/src/window.hh +++ b/src/window.hh @@ -52,7 +52,7 @@ private: void run_hook_in_own_context(const String& hook_name, StringView param); - safe_ptr m_buffer; + SafePtr m_buffer; CharCoord m_position; CharCoord m_dimensions; diff --git a/src/word_db.hh b/src/word_db.hh index 819550681..d560b560b 100644 --- a/src/word_db.hh +++ b/src/word_db.hh @@ -50,9 +50,9 @@ private: int refcount; }; using WordToInfo = UnorderedMap; - using Lines = Vector, MemoryDomain::WordDB>; + using Lines = Vector, MemoryDomain::WordDB>; - safe_ptr m_buffer; + SafePtr m_buffer; size_t m_timestamp; WordToInfo m_words; Lines m_lines;