mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-30 22:54:35 +03:00
JSON: Port JsonArray and JsonObject serialization to serializers
This way, primitive JsonValue serialization is still handled by JsonValue::serialize(), but JsonArray and JsonObject serialization always goes through serializer classes. This is no less efficient if you have the whole JSON in memory already.
This commit is contained in:
parent
56f5c14d86
commit
216b7b3b80
Notes:
sideshowbarker
2024-07-19 12:29:34 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/216b7b3b80d Pull-request: https://github.com/SerenityOS/serenity/pull/489 Reviewed-by: https://github.com/awesomekling
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/JsonArraySerializer.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
@ -68,13 +69,8 @@ private:
|
||||
template<typename Builder>
|
||||
inline void JsonArray::serialize(Builder& builder) const
|
||||
{
|
||||
builder.append('[');
|
||||
for (int i = 0; i < m_values.size(); ++i) {
|
||||
m_values[i].serialize(builder);
|
||||
if (i != size() - 1)
|
||||
builder.append(',');
|
||||
}
|
||||
builder.append(']');
|
||||
JsonArraySerializer serializer { builder };
|
||||
for_each([&](auto& value) { serializer.add(value); });
|
||||
}
|
||||
|
||||
template<typename Builder>
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/JsonValue.h>
|
||||
|
||||
namespace AK {
|
||||
@ -79,19 +80,10 @@ private:
|
||||
template<typename Builder>
|
||||
inline void JsonObject::serialize(Builder& builder) const
|
||||
{
|
||||
int index = 0;
|
||||
builder.append('{');
|
||||
JsonObjectSerializer serializer { builder };
|
||||
for_each_member([&](auto& key, auto& value) {
|
||||
builder.append('"');
|
||||
builder.append(key);
|
||||
builder.append('"');
|
||||
builder.append(':');
|
||||
value.serialize(builder);
|
||||
if (index != size() - 1)
|
||||
builder.append(',');
|
||||
++index;
|
||||
serializer.add(key, value);
|
||||
});
|
||||
builder.append('}');
|
||||
}
|
||||
|
||||
template<typename Builder>
|
||||
|
Loading…
Reference in New Issue
Block a user