Json: Add serializer fast-path for string values

Passing these through the generic JsonValue path was causing us to
instantiate temporary JsonValues that incurred a heap allocation.
This avoids that by adding specialized overloads for string types.
This commit is contained in:
Andreas Kling 2019-09-04 14:39:08 +02:00
parent 14a228a6f8
commit cc98ea1956
2 changed files with 48 additions and 0 deletions

View file

@ -31,6 +31,30 @@ public:
value.serialize(m_builder);
}
void add(const StringView& value)
{
begin_item();
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
void add(const String& value)
{
begin_item();
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
void add(const char* value)
{
begin_item();
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
JsonArraySerializer<Builder> add_array()
{
begin_item();

View file

@ -29,6 +29,30 @@ public:
value.serialize(m_builder);
}
void add(const StringView& key, const StringView& value)
{
begin_item(key);
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
void add(const StringView& key, const String& value)
{
begin_item(key);
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
void add(const StringView& key, const char* value)
{
begin_item(key);
m_builder.append('"');
m_builder.append(value);
m_builder.append('"');
}
JsonArraySerializer<Builder> add_array(const StringView& key)
{
begin_item(key);