mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:24:58 +00:00
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:
parent
14a228a6f8
commit
cc98ea1956
2 changed files with 48 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue