diff --git a/src/buffer.cc b/src/buffer.cc index 51b54fde..60c9fdce 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -28,7 +28,7 @@ Buffer::Buffer(String name, Flags flags, BufferLines lines, options().register_watcher(*this); if (lines.empty()) - lines.emplace_back(StringStorage::create("\n")); + lines.emplace_back(StringData::create("\n")); #ifdef KAK_DEBUG for (auto& line : lines) @@ -170,7 +170,7 @@ void Buffer::reload(BufferLines lines, time_t fs_timestamp) } if (lines.empty()) - lines.emplace_back(StringStorage::create("\n")); + lines.emplace_back(StringData::create("\n")); for (size_t l = 0; l < lines.size(); ++l) { @@ -267,12 +267,12 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content) { if (content[i] == '\n') { - m_lines.push_back(StringStorage::create(content.substr(start, i + 1 - start))); + m_lines.push_back(StringData::create(content.substr(start, i + 1 - start))); start = i + 1; } } if (start != content.length()) - m_lines.push_back(StringStorage::create(content.substr(start))); + m_lines.push_back(StringData::create(content.substr(start))); begin = pos.column == 0 ? pos : ByteCoord{ pos.line + 1, 0 }; end = ByteCoord{ line_count(), 0 }; @@ -292,16 +292,16 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content) { StringView line_content = content.substr(start, i + 1 - start); if (start == 0) - new_lines.emplace_back(StringStorage::create(prefix + line_content)); + new_lines.emplace_back(StringData::create(prefix + line_content)); else - new_lines.push_back(StringStorage::create(line_content)); + new_lines.push_back(StringData::create(line_content)); start = i + 1; } } if (start == 0) - new_lines.emplace_back(StringStorage::create(prefix + content + suffix)); + new_lines.emplace_back(StringData::create(prefix + content + suffix)); else if (start != content.length() or not suffix.empty()) - new_lines.emplace_back(StringStorage::create(content.substr(start) + suffix)); + new_lines.emplace_back(StringData::create(content.substr(start) + suffix)); LineCount last_line = pos.line + new_lines.size() - 1; @@ -331,7 +331,7 @@ ByteCoord Buffer::do_erase(ByteCoord begin, ByteCoord end) if (new_line.length() != 0) { m_lines.erase(m_lines.begin() + (int)begin.line, m_lines.begin() + (int)end.line); - m_lines.get_storage(begin.line) = StringStorage::create(new_line); + m_lines.get_storage(begin.line) = StringData::create(new_line); next = begin; } else diff --git a/src/buffer.hh b/src/buffer.hh index 4c4a6ac5..4b8ba90e 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -59,7 +59,7 @@ private: 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]; } - RefPtr 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]] - RefPtr& get_storage(LineCount line) + RefPtr& get_storage(LineCount line) { return BufferLines::operator[]((int)line); } [[gnu::always_inline]] - const RefPtr& 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_utils.cc b/src/buffer_utils.cc index c768a9eb..88f7d4f8 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -66,7 +66,7 @@ Buffer* create_buffer_from_data(StringView data, StringView name, while (line_end < data.end() and *line_end != '\r' and *line_end != '\n') ++line_end; - lines.emplace_back(StringStorage::create({pos, line_end}, '\n')); + lines.emplace_back(StringData::create({pos, line_end}, '\n')); if (line_end+1 != data.end() and *line_end == '\r' and *(line_end+1) == '\n') { diff --git a/src/shared_string.hh b/src/shared_string.hh index 782f1674..73a21f6b 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -9,13 +9,13 @@ namespace Kakoune { -struct StringStorage : UseMemoryDomain +struct StringData : UseMemoryDomain { int refcount; int length; - StringStorage() = default; - constexpr StringStorage(int refcount, int length) : refcount(refcount), length(length) {} + StringData() = default; + constexpr StringData(int refcount, int length) : refcount(refcount), length(length) {} [[gnu::always_inline]] char* data() { return reinterpret_cast(this + 1); } @@ -24,55 +24,55 @@ struct StringStorage : UseMemoryDomain [[gnu::always_inline]] StringView strview() const { return {data(), length}; } - static RefPtr create(StringView str, char back = 0) + static RefPtr create(StringView str, char back = 0) { const int len = (int)str.length() + (back != 0 ? 1 : 0); - void* ptr = StringStorage::operator new(sizeof(StringStorage) + len + 1); - StringStorage* res = reinterpret_cast(ptr); + void* ptr = StringData::operator new(sizeof(StringData) + len + 1); + StringData* res = reinterpret_cast(ptr); std::copy(str.begin(), str.end(), res->data()); res->refcount = 0; res->length = len; if (back != 0) res->data()[len-1] = back; res->data()[len] = 0; - return RefPtr(res); + return RefPtr(res); } - static void destroy(StringStorage* s) + static void destroy(StringData* s) { - StringStorage::operator delete(s, sizeof(StringStorage) + s->length + 1); + StringData::operator delete(s, sizeof(StringData) + s->length + 1); } - friend void inc_ref_count(StringStorage* s, void*) + friend void inc_ref_count(StringData* s, void*) { if (s->refcount != -1) ++s->refcount; } - friend void dec_ref_count(StringStorage* s, void*) + friend void dec_ref_count(StringData* s, void*) { if (s->refcount != -1 and --s->refcount == 0) - StringStorage::destroy(s); + StringData::destroy(s); } }; -inline RefPtr operator"" _ss(const char* ptr, size_t len) +inline RefPtr operator"" _ss(const char* ptr, size_t len) { - return StringStorage::create({ptr, (int)len}); + return StringData::create({ptr, (int)len}); } template -struct StaticStringStorage : StringStorage +struct StaticStringData : StringData { template constexpr - StaticStringStorage(const char (&literal)[len], IndexSequence) - : StringStorage{-1, len}, data{literal[I]...} {} + StaticStringData(const char (&literal)[len], IndexSequence) + : StringData{-1, len}, data{literal[I]...} {} const char data[len]; }; template -constexpr StaticStringStorage static_storage(const char (&literal)[len]) +constexpr StaticStringData static_storage(const char (&literal)[len]) { return { literal, make_index_sequence() }; } @@ -85,7 +85,7 @@ public: { if (not str.empty()) { - m_storage = StringStorage::create(str); + m_storage = StringData::create(str); StringView::operator=(m_storage->strview()); } } @@ -103,15 +103,15 @@ public: return SharedString{StringView::substr(from, length), m_storage}; } - explicit SharedString(RefPtr storage) + explicit SharedString(RefPtr storage) : StringView{storage->strview()}, m_storage(std::move(storage)) {} private: - SharedString(StringView str, RefPtr storage) + SharedString(StringView str, RefPtr storage) : StringView{str}, m_storage(std::move(storage)) {} friend class StringRegistry; - RefPtr m_storage; + RefPtr m_storage; }; inline size_t hash_value(const SharedString& str) @@ -127,7 +127,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/word_db.hh b/src/word_db.hh index d560b560..b3b10e65 100644 --- a/src/word_db.hh +++ b/src/word_db.hh @@ -50,7 +50,7 @@ private: int refcount; }; using WordToInfo = UnorderedMap; - using Lines = Vector, MemoryDomain::WordDB>; + using Lines = Vector, MemoryDomain::WordDB>; SafePtr m_buffer; size_t m_timestamp;