summaryrefslogtreecommitdiff
path: root/AK/Format.h
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-10-21 19:09:38 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-21 22:19:50 +0200
commit39a74676bd7b14750b133aaa05a4dbdc80f4d304 (patch)
treee571f655d7712bca1af5aaf160909462fc82be62 /AK/Format.h
parent018c4e0e7e54ad49d365ba1463cbc6dc83ea02e7 (diff)
downloadserenity-39a74676bd7b14750b133aaa05a4dbdc80f4d304.zip
AK: Avoid temporary String allocation in Formatter<FormatString>
Creating a String object from the formatted data is unnecessary, as it immediately gets turned into a StringView anyways. With this change, we will no longer allocate on the heap when printing `VirtualAddress`, `VirtualRange` and `InodeIdentifier` objects, which is a step towards stronger OOM hardening.
Diffstat (limited to 'AK/Format.h')
-rw-r--r--AK/Format.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/AK/Format.h b/AK/Format.h
index 953e062b8b..c1c10d0b9f 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -595,7 +595,7 @@ struct Formatter<FormatIfSupported<T>> : __FormatIfSupported<T, HasFormatter<T>>
struct FormatString {
};
template<>
-struct Formatter<FormatString> : Formatter<String> {
+struct Formatter<FormatString> : Formatter<StringView> {
template<typename... Parameters>
void format(FormatBuilder& builder, StringView fmtstr, const Parameters&... parameters)
{