1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

Userland: Avoid a bunch of JsonObject copies

JsonValue::as_object() returns a reference.
This commit is contained in:
Linus Groh 2021-05-31 17:59:02 +01:00
parent a6248101e2
commit 16d51d78c0
11 changed files with 12 additions and 13 deletions

View file

@ -86,7 +86,7 @@ static void fill_mounts(Vector<MountInfo>& output)
VERIFY(json.has_value());
json.value().as_array().for_each([&output](auto& value) {
auto filesystem_object = value.as_object();
auto& filesystem_object = value.as_object();
MountInfo mount_info;
mount_info.mount_point = filesystem_object.get("mount_point").to_string();
mount_info.source = filesystem_object.get("source").as_string_or("none");

View file

@ -7,7 +7,6 @@
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/JsonObject.h>
#include <AK/String.h>
#include <LibCore/File.h>
#include <stdio.h>
@ -24,7 +23,7 @@ int main()
auto json = JsonValue::from_string(file_contents);
VERIFY(json.has_value());
json.value().as_array().for_each([](auto& value) {
auto if_object = value.as_object();
auto& if_object = value.as_object();
auto ip_address = if_object.get("ip_address").to_string();
auto mac_address = if_object.get("mac_address").to_string();

View file

@ -56,7 +56,7 @@ int main(int argc, char** argv)
VERIFY(json_result.has_value());
auto json = json_result.value().as_array();
json.for_each([](auto& value) {
auto fs_object = value.as_object();
auto& fs_object = value.as_object();
auto fs = fs_object.get("class_name").to_string();
auto total_block_count = fs_object.get("total_block_count").to_u64();
auto free_block_count = fs_object.get("free_block_count").to_u64();

View file

@ -24,7 +24,7 @@ public:
{
if (!value.is_object())
return {};
auto entry = value.as_object();
auto& entry = value.as_object();
Quote q;
if (!entry.has("quote") || !entry.has("author") || !entry.has("utc_time") || !entry.has("url"))
return {};

View file

@ -48,7 +48,7 @@ int main(int argc, char** argv)
auto json = JsonValue::from_string(file_contents);
VERIFY(json.has_value());
json.value().as_array().for_each([](auto& value) {
auto if_object = value.as_object();
auto& if_object = value.as_object();
auto name = if_object.get("name").to_string();
auto class_name = if_object.get("class_name").to_string();

View file

@ -68,7 +68,7 @@ void print(const JsonValue& value, int spaces_per_indent, int indent, bool use_c
{
if (value.is_object()) {
size_t printed_members = 0;
auto object = value.as_object();
auto& object = value.as_object();
outln("{{");
object.for_each_member([&](auto& member_name, auto& member_value) {
++printed_members;

View file

@ -42,7 +42,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
auto json = JsonValue::from_string(file_contents);
VERIFY(json.has_value());
json.value().as_array().for_each([](auto& value) {
auto handler = value.as_object();
auto& handler = value.as_object();
auto purpose = handler.get("purpose").to_string();
auto interrupt = handler.get("interrupt_line").to_string();
auto controller = handler.get("controller").to_string();

View file

@ -69,7 +69,7 @@ int main(int argc, char** argv)
auto json = JsonValue::from_string(file_contents);
VERIFY(json.has_value());
json.value().as_array().for_each([db, format](auto& value) {
auto dev = value.as_object();
auto& dev = value.as_object();
auto seg = dev.get("seg").to_u32();
auto bus = dev.get("bus").to_u32();
auto device = dev.get("device").to_u32();

View file

@ -129,7 +129,7 @@ static bool print_mounts()
VERIFY(json.has_value());
json.value().as_array().for_each([](auto& value) {
auto fs_object = value.as_object();
auto& fs_object = value.as_object();
auto class_name = fs_object.get("class_name").to_string();
auto mount_point = fs_object.get("mount_point").to_string();
auto source = fs_object.get("source").as_string_or("none");

View file

@ -123,7 +123,7 @@ int main(int argc, char** argv)
});
for (auto& value : sorted_regions) {
auto if_object = value.as_object();
auto& if_object = value.as_object();
auto bytes_in = if_object.get("bytes_in").to_string();
auto bytes_out = if_object.get("bytes_out").to_string();
@ -174,7 +174,7 @@ int main(int argc, char** argv)
});
for (auto& value : sorted_regions) {
auto if_object = value.as_object();
auto& if_object = value.as_object();
auto local_address = if_object.get("local_address").to_string();
auto local_port = if_object.get("local_port").to_string();

View file

@ -60,7 +60,7 @@ int main(int argc, char** argv)
});
for (auto& value : sorted_regions) {
auto map = value.as_object();
auto& map = value.as_object();
auto address = map.get("address").to_int();
auto size = map.get("size").to_string();