From 97b76756707371dda8ae74c95274266a21d217e3 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Sun, 6 Oct 2024 09:14:56 +0100 Subject: [PATCH] Remove some unneeded headers (#680) * Removed unneeded headers This removes some unneeded headers from the headers. * Remove use of std::string This stack allocates and copies a c-string to replace the calls to std::string. --- .../backend_helpers/largebuddyrange.h | 2 -- src/snmalloc/ds/combininglock.h | 1 - src/snmalloc/ds/flaglock.h | 1 - src/snmalloc/ds/singleton.h | 2 -- src/snmalloc/ds_core/helpers.h | 2 +- src/snmalloc/ds_core/redblacktree.h | 25 ++++++++++++++++--- src/snmalloc/mem/freelist_queue.h | 1 - src/snmalloc/mem/remoteallocator.h | 2 ++ src/snmalloc/pal/pal_consts.h | 1 - src/snmalloc/pal/pal_ds.h | 1 - src/test/func/redblack/redblack.cc | 1 - src/test/perf/startup/startup.cc | 1 + 12 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/snmalloc/backend_helpers/largebuddyrange.h b/src/snmalloc/backend_helpers/largebuddyrange.h index e85e06f2..803eb484 100644 --- a/src/snmalloc/backend_helpers/largebuddyrange.h +++ b/src/snmalloc/backend_helpers/largebuddyrange.h @@ -6,8 +6,6 @@ #include "empty_range.h" #include "range_helpers.h" -#include - namespace snmalloc { /** diff --git a/src/snmalloc/ds/combininglock.h b/src/snmalloc/ds/combininglock.h index 338c94b4..1857713d 100644 --- a/src/snmalloc/ds/combininglock.h +++ b/src/snmalloc/ds/combininglock.h @@ -4,7 +4,6 @@ #include "../pal/pal.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/ds/flaglock.h b/src/snmalloc/ds/flaglock.h index cd314f90..c711020d 100644 --- a/src/snmalloc/ds/flaglock.h +++ b/src/snmalloc/ds/flaglock.h @@ -4,7 +4,6 @@ #include "../pal/pal.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/ds/singleton.h b/src/snmalloc/ds/singleton.h index 375a82f8..174128e7 100644 --- a/src/snmalloc/ds/singleton.h +++ b/src/snmalloc/ds/singleton.h @@ -3,9 +3,7 @@ #include "../ds_core/ds_core.h" #include "flaglock.h" -#include #include -#include #include namespace snmalloc diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index e79c5695..fa24f29c 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include namespace snmalloc diff --git a/src/snmalloc/ds_core/redblacktree.h b/src/snmalloc/ds_core/redblacktree.h index 8b981aba..59ad4c8d 100644 --- a/src/snmalloc/ds_core/redblacktree.h +++ b/src/snmalloc/ds_core/redblacktree.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace snmalloc { @@ -439,9 +438,27 @@ namespace snmalloc depth); if (!(get_dir(true, curr).is_null() && get_dir(false, curr).is_null())) { - auto s_indent = std::string(indent); - print(get_dir(true, curr), (s_indent + "|").c_str(), depth + 1); - print(get_dir(false, curr), (s_indent + " ").c_str(), depth + 1); + // As the tree should be balanced, the depth should not exceed 128 if + // there are 2^64 elements in the tree. This is a debug feature, and + // it would be impossible to debug something of this size, so this is + // considerably larger than required. + // If there is a bug that leads to an unbalanced tree, this might be + // insufficient to accurately display the tree, but it will still be + // memory safe as the search code is bounded by the string size. + static constexpr size_t max_depth = 128; + char s_indent[max_depth]; + size_t end = 0; + for (; end < max_depth - 1; end++) + { + if (indent[end] == 0) + break; + s_indent[end] = indent[end]; + } + s_indent[end] = '|'; + s_indent[end + 1] = 0; + print(get_dir(true, curr), s_indent, depth + 1); + s_indent[end] = ' '; + print(get_dir(false, curr), s_indent, depth + 1); } } } diff --git a/src/snmalloc/mem/freelist_queue.h b/src/snmalloc/mem/freelist_queue.h index e7dd813e..fb38f7c8 100644 --- a/src/snmalloc/mem/freelist_queue.h +++ b/src/snmalloc/mem/freelist_queue.h @@ -3,7 +3,6 @@ #include "../ds/ds.h" #include "freelist.h" -#include #include namespace snmalloc diff --git a/src/snmalloc/mem/remoteallocator.h b/src/snmalloc/mem/remoteallocator.h index 0a72aa31..a207d12f 100644 --- a/src/snmalloc/mem/remoteallocator.h +++ b/src/snmalloc/mem/remoteallocator.h @@ -2,6 +2,8 @@ #include "freelist_queue.h" +#include + namespace snmalloc { class RemoteMessageAssertions; diff --git a/src/snmalloc/pal/pal_consts.h b/src/snmalloc/pal/pal_consts.h index 3c7fd58d..5679c336 100644 --- a/src/snmalloc/pal/pal_consts.h +++ b/src/snmalloc/pal/pal_consts.h @@ -3,7 +3,6 @@ #include "../ds_core/ds_core.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/pal/pal_ds.h b/src/snmalloc/pal/pal_ds.h index 3da37cf4..008d1f2c 100644 --- a/src/snmalloc/pal/pal_ds.h +++ b/src/snmalloc/pal/pal_ds.h @@ -3,7 +3,6 @@ #include "../ds_core/ds_core.h" #include -#include namespace snmalloc { diff --git a/src/test/func/redblack/redblack.cc b/src/test/func/redblack/redblack.cc index f13c72eb..40ce667c 100644 --- a/src/test/func/redblack/redblack.cc +++ b/src/test/func/redblack/redblack.cc @@ -4,7 +4,6 @@ #include "test/xoroshiro.h" #include -#include #include #include diff --git a/src/test/perf/startup/startup.cc b/src/test/perf/startup/startup.cc index 437128f0..46e18f90 100644 --- a/src/test/perf/startup/startup.cc +++ b/src/test/perf/startup/startup.cc @@ -3,6 +3,7 @@ #include "test/usage.h" #include "test/xoroshiro.h" +#include #include #include #include