From f1e86d78d3ba8575cbe6edd91b2b30c013132e13 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 24 Sep 2024 11:46:08 +0100 Subject: [PATCH] Remove use of std::string This stack allocates and copies a c-string to replace the calls to std::string. --- src/snmalloc/ds_core/redblacktree.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/snmalloc/ds_core/redblacktree.h b/src/snmalloc/ds_core/redblacktree.h index 8b981aba9..3500da9ca 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,19 @@ 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); + char s_indent[128]; + size_t end=0; + for (; end < 127; 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); } } }