mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-28 06:08:05 +03:00
rename StringStorage to StringData
This commit is contained in:
parent
092dcd174f
commit
98972c18b7
@ -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
|
||||
|
@ -59,7 +59,7 @@ private:
|
||||
ByteCoord m_coord;
|
||||
};
|
||||
|
||||
using BufferLines = Vector<RefPtr<StringStorage>, MemoryDomain::BufferContent>;
|
||||
using BufferLines = Vector<RefPtr<StringData>, 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<StringStorage> line_storage(LineCount line) const
|
||||
RefPtr<StringData> 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<StringStorage>& get_storage(LineCount line)
|
||||
RefPtr<StringData>& get_storage(LineCount line)
|
||||
{ return BufferLines::operator[]((int)line); }
|
||||
|
||||
[[gnu::always_inline]]
|
||||
const RefPtr<StringStorage>& get_storage(LineCount line) const
|
||||
const RefPtr<StringData>& get_storage(LineCount line) const
|
||||
{ return BufferLines::operator[]((int)line); }
|
||||
|
||||
[[gnu::always_inline]]
|
||||
|
@ -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')
|
||||
{
|
||||
|
@ -9,13 +9,13 @@
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
struct StringStorage : UseMemoryDomain<MemoryDomain::SharedString>
|
||||
struct StringData : UseMemoryDomain<MemoryDomain::SharedString>
|
||||
{
|
||||
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<char*>(this + 1); }
|
||||
@ -24,55 +24,55 @@ struct StringStorage : UseMemoryDomain<MemoryDomain::SharedString>
|
||||
[[gnu::always_inline]]
|
||||
StringView strview() const { return {data(), length}; }
|
||||
|
||||
static RefPtr<StringStorage> create(StringView str, char back = 0)
|
||||
static RefPtr<StringData> 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<StringStorage*>(ptr);
|
||||
void* ptr = StringData::operator new(sizeof(StringData) + len + 1);
|
||||
StringData* res = reinterpret_cast<StringData*>(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<StringStorage>(res);
|
||||
return RefPtr<StringData>(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<StringStorage> operator"" _ss(const char* ptr, size_t len)
|
||||
inline RefPtr<StringData> operator"" _ss(const char* ptr, size_t len)
|
||||
{
|
||||
return StringStorage::create({ptr, (int)len});
|
||||
return StringData::create({ptr, (int)len});
|
||||
}
|
||||
|
||||
template<size_t len>
|
||||
struct StaticStringStorage : StringStorage
|
||||
struct StaticStringData : StringData
|
||||
{
|
||||
template<size_t... I> constexpr
|
||||
StaticStringStorage(const char (&literal)[len], IndexSequence<I...>)
|
||||
: StringStorage{-1, len}, data{literal[I]...} {}
|
||||
StaticStringData(const char (&literal)[len], IndexSequence<I...>)
|
||||
: StringData{-1, len}, data{literal[I]...} {}
|
||||
|
||||
const char data[len];
|
||||
};
|
||||
|
||||
template<size_t len>
|
||||
constexpr StaticStringStorage<len> static_storage(const char (&literal)[len])
|
||||
constexpr StaticStringData<len> static_storage(const char (&literal)[len])
|
||||
{
|
||||
return { literal, make_index_sequence<len>() };
|
||||
}
|
||||
@ -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<StringStorage> storage)
|
||||
explicit SharedString(RefPtr<StringData> storage)
|
||||
: StringView{storage->strview()}, m_storage(std::move(storage)) {}
|
||||
|
||||
private:
|
||||
SharedString(StringView str, RefPtr<StringStorage> storage)
|
||||
SharedString(StringView str, RefPtr<StringData> storage)
|
||||
: StringView{str}, m_storage(std::move(storage)) {}
|
||||
|
||||
friend class StringRegistry;
|
||||
RefPtr<StringStorage> m_storage;
|
||||
RefPtr<StringData> m_storage;
|
||||
};
|
||||
|
||||
inline size_t hash_value(const SharedString& str)
|
||||
@ -127,7 +127,7 @@ public:
|
||||
void purge_unused();
|
||||
|
||||
private:
|
||||
UnorderedMap<StringView, RefPtr<StringStorage>, MemoryDomain::SharedString> m_strings;
|
||||
UnorderedMap<StringView, RefPtr<StringData>, MemoryDomain::SharedString> m_strings;
|
||||
};
|
||||
|
||||
inline SharedString intern(StringView str)
|
||||
|
@ -50,7 +50,7 @@ private:
|
||||
int refcount;
|
||||
};
|
||||
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
|
||||
using Lines = Vector<RefPtr<StringStorage>, MemoryDomain::WordDB>;
|
||||
using Lines = Vector<RefPtr<StringData>, MemoryDomain::WordDB>;
|
||||
|
||||
SafePtr<const Buffer> m_buffer;
|
||||
size_t m_timestamp;
|
||||
|
Loading…
Reference in New Issue
Block a user