mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
Userland: Avoid a bunch of JsonObject copies
JsonValue::as_object() returns a reference.
This commit is contained in:
parent
a6248101e2
commit
16d51d78c0
11 changed files with 12 additions and 13 deletions
|
@ -86,7 +86,7 @@ static void fill_mounts(Vector<MountInfo>& output)
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
|
|
||||||
json.value().as_array().for_each([&output](auto& 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;
|
MountInfo mount_info;
|
||||||
mount_info.mount_point = filesystem_object.get("mount_point").to_string();
|
mount_info.mount_point = filesystem_object.get("mount_point").to_string();
|
||||||
mount_info.source = filesystem_object.get("source").as_string_or("none");
|
mount_info.source = filesystem_object.get("source").as_string_or("none");
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/String.h>
|
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ int main()
|
||||||
auto json = JsonValue::from_string(file_contents);
|
auto json = JsonValue::from_string(file_contents);
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
json.value().as_array().for_each([](auto& 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 ip_address = if_object.get("ip_address").to_string();
|
||||||
auto mac_address = if_object.get("mac_address").to_string();
|
auto mac_address = if_object.get("mac_address").to_string();
|
||||||
|
|
|
@ -56,7 +56,7 @@ int main(int argc, char** argv)
|
||||||
VERIFY(json_result.has_value());
|
VERIFY(json_result.has_value());
|
||||||
auto json = json_result.value().as_array();
|
auto json = json_result.value().as_array();
|
||||||
json.for_each([](auto& value) {
|
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 fs = fs_object.get("class_name").to_string();
|
||||||
auto total_block_count = fs_object.get("total_block_count").to_u64();
|
auto total_block_count = fs_object.get("total_block_count").to_u64();
|
||||||
auto free_block_count = fs_object.get("free_block_count").to_u64();
|
auto free_block_count = fs_object.get("free_block_count").to_u64();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
{
|
{
|
||||||
if (!value.is_object())
|
if (!value.is_object())
|
||||||
return {};
|
return {};
|
||||||
auto entry = value.as_object();
|
auto& entry = value.as_object();
|
||||||
Quote q;
|
Quote q;
|
||||||
if (!entry.has("quote") || !entry.has("author") || !entry.has("utc_time") || !entry.has("url"))
|
if (!entry.has("quote") || !entry.has("author") || !entry.has("utc_time") || !entry.has("url"))
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc, char** argv)
|
||||||
auto json = JsonValue::from_string(file_contents);
|
auto json = JsonValue::from_string(file_contents);
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
json.value().as_array().for_each([](auto& 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 name = if_object.get("name").to_string();
|
||||||
auto class_name = if_object.get("class_name").to_string();
|
auto class_name = if_object.get("class_name").to_string();
|
||||||
|
|
|
@ -68,7 +68,7 @@ void print(const JsonValue& value, int spaces_per_indent, int indent, bool use_c
|
||||||
{
|
{
|
||||||
if (value.is_object()) {
|
if (value.is_object()) {
|
||||||
size_t printed_members = 0;
|
size_t printed_members = 0;
|
||||||
auto object = value.as_object();
|
auto& object = value.as_object();
|
||||||
outln("{{");
|
outln("{{");
|
||||||
object.for_each_member([&](auto& member_name, auto& member_value) {
|
object.for_each_member([&](auto& member_name, auto& member_value) {
|
||||||
++printed_members;
|
++printed_members;
|
||||||
|
|
|
@ -42,7 +42,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||||
auto json = JsonValue::from_string(file_contents);
|
auto json = JsonValue::from_string(file_contents);
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
json.value().as_array().for_each([](auto& 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 purpose = handler.get("purpose").to_string();
|
||||||
auto interrupt = handler.get("interrupt_line").to_string();
|
auto interrupt = handler.get("interrupt_line").to_string();
|
||||||
auto controller = handler.get("controller").to_string();
|
auto controller = handler.get("controller").to_string();
|
||||||
|
|
|
@ -69,7 +69,7 @@ int main(int argc, char** argv)
|
||||||
auto json = JsonValue::from_string(file_contents);
|
auto json = JsonValue::from_string(file_contents);
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
json.value().as_array().for_each([db, format](auto& 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 seg = dev.get("seg").to_u32();
|
||||||
auto bus = dev.get("bus").to_u32();
|
auto bus = dev.get("bus").to_u32();
|
||||||
auto device = dev.get("device").to_u32();
|
auto device = dev.get("device").to_u32();
|
||||||
|
|
|
@ -129,7 +129,7 @@ static bool print_mounts()
|
||||||
VERIFY(json.has_value());
|
VERIFY(json.has_value());
|
||||||
|
|
||||||
json.value().as_array().for_each([](auto& 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 class_name = fs_object.get("class_name").to_string();
|
||||||
auto mount_point = fs_object.get("mount_point").to_string();
|
auto mount_point = fs_object.get("mount_point").to_string();
|
||||||
auto source = fs_object.get("source").as_string_or("none");
|
auto source = fs_object.get("source").as_string_or("none");
|
||||||
|
|
|
@ -123,7 +123,7 @@ int main(int argc, char** argv)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto& value : sorted_regions) {
|
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_in = if_object.get("bytes_in").to_string();
|
||||||
auto bytes_out = if_object.get("bytes_out").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) {
|
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_address = if_object.get("local_address").to_string();
|
||||||
auto local_port = if_object.get("local_port").to_string();
|
auto local_port = if_object.get("local_port").to_string();
|
||||||
|
|
|
@ -60,7 +60,7 @@ int main(int argc, char** argv)
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto& value : sorted_regions) {
|
for (auto& value : sorted_regions) {
|
||||||
auto map = value.as_object();
|
auto& map = value.as_object();
|
||||||
auto address = map.get("address").to_int();
|
auto address = map.get("address").to_int();
|
||||||
auto size = map.get("size").to_string();
|
auto size = map.get("size").to_string();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue