From f8d643284e293978b4a612e901691fad17461d6e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 24 Jan 2021 19:15:34 +0100 Subject: [PATCH] pmap: Sort memory regions in output This makes the program 100% nicer to use. :^) --- Userland/Utilities/pmap.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/pmap.cpp b/Userland/Utilities/pmap.cpp index 2706b3fc4a5..d25edcb2947 100644 --- a/Userland/Utilities/pmap.cpp +++ b/Userland/Utilities/pmap.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -70,7 +71,13 @@ int main(int argc, char** argv) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); ASSERT(json.has_value()); - json.value().as_array().for_each([](auto& value) { + + Vector sorted_regions = json.value().as_array().values(); + quick_sort(sorted_regions, [](auto& a, auto& b) { + return a.as_object().get("address").to_u32() < b.as_object().get("address").to_u32(); + }); + + for (auto& value : sorted_regions) { auto map = value.as_object(); auto address = map.get("address").to_int(); auto size = map.get("size").to_string(); @@ -100,7 +107,7 @@ int main(int argc, char** argv) auto name = map.get("name").to_string(); printf("%-20s ", name.characters()); printf("\n"); - }); + } return 0; }