From 05dae23f1807f941643db8bfadac1226bf1df6e8 Mon Sep 17 00:00:00 2001 From: Yufeng Ying Date: Thu, 19 Jun 2025 18:22:49 +0800 Subject: [PATCH] Remove dependency of variant.h in print_string.h Co-authored-by: Lukas Tenbrink Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- core/string/print_string.cpp | 12 +++++-- core/string/print_string.h | 31 +++++++------------ core/templates/rid_owner.h | 2 +- modules/jolt_physics/jolt_globals.cpp | 2 +- .../linuxbsd/wayland/detect_prime_egl.cpp | 2 +- platform/linuxbsd/x11/detect_prime_x11.cpp | 2 +- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/core/string/print_string.cpp b/core/string/print_string.cpp index 177ddc3c77a..7f2607b0b3a 100644 --- a/core/string/print_string.cpp +++ b/core/string/print_string.cpp @@ -341,6 +341,14 @@ bool is_print_verbose_enabled() { return OS::get_singleton()->is_stdout_verbose(); } -String stringify_variants(const Variant &p_var) { - return p_var.operator String(); +String stringify_variants(const Span &p_vars) { + if (p_vars.is_empty()) { + return String(); + } + String result = String(p_vars[0]); + for (const Variant &v : Span(p_vars.ptr() + 1, p_vars.size() - 1)) { + result += ' '; + result += v.operator String(); + } + return result; } diff --git a/core/string/print_string.h b/core/string/print_string.h index 1914d36ca65..7f44e8a5ebe 100644 --- a/core/string/print_string.h +++ b/core/string/print_string.h @@ -30,7 +30,9 @@ #pragma once -#include "core/variant/variant.h" +#include "core/string/ustring.h" + +class Variant; extern void (*_print_func)(String); @@ -45,12 +47,7 @@ struct PrintHandlerList { PrintHandlerList() {} }; -String stringify_variants(const Variant &p_var); - -template -String stringify_variants(const Variant &p_var, Args... p_args) { - return p_var.operator String() + " " + stringify_variants(p_args...); -} +String stringify_variants(const Span &p_vars); void add_print_handler(PrintHandlerList *p_handler); void remove_print_handler(const PrintHandlerList *p_handler); @@ -69,20 +66,14 @@ extern bool is_print_verbose_enabled(); } \ } -inline void print_line(const Variant &v) { - __print_line(stringify_variants(v)); -} - -inline void print_line_rich(const Variant &v) { - __print_line_rich(stringify_variants(v)); +template +void print_line(Args... p_args) { + Variant variants[sizeof...(p_args)] = { p_args... }; + __print_line(stringify_variants(Span(variants))); } template -void print_line(const Variant &p_var, Args... p_args) { - __print_line(stringify_variants(p_var, p_args...)); -} - -template -void print_line_rich(const Variant &p_var, Args... p_args) { - __print_line_rich(stringify_variants(p_var, p_args...)); +void print_line_rich(Args... p_args) { + Variant variants[sizeof...(p_args)] = { p_args... }; + __print_line_rich(stringify_variants(Span(variants))); } diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index 02b26141ac2..ddbe812f86e 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -34,8 +34,8 @@ #include "core/os/mutex.h" #include "core/string/print_string.h" #include "core/templates/local_vector.h" -#include "core/templates/rid.h" #include "core/templates/safe_refcount.h" +#include "core/variant/variant.h" #include #include // IWYU pragma: keep // Used in macro. diff --git a/modules/jolt_physics/jolt_globals.cpp b/modules/jolt_physics/jolt_globals.cpp index 53f1fef9510..bde79a23ecd 100644 --- a/modules/jolt_physics/jolt_globals.cpp +++ b/modules/jolt_physics/jolt_globals.cpp @@ -35,8 +35,8 @@ #include "shapes/jolt_custom_ray_shape.h" #include "shapes/jolt_custom_user_data_shape.h" -#include "core/os/memory.h" #include "core/string/print_string.h" +#include "core/variant/variant.h" #include "Jolt/Jolt.h" diff --git a/platform/linuxbsd/wayland/detect_prime_egl.cpp b/platform/linuxbsd/wayland/detect_prime_egl.cpp index f5e94925b4f..8c697aa1cd6 100644 --- a/platform/linuxbsd/wayland/detect_prime_egl.cpp +++ b/platform/linuxbsd/wayland/detect_prime_egl.cpp @@ -34,7 +34,7 @@ #include "detect_prime_egl.h" #include "core/string/print_string.h" -#include "core/string/ustring.h" +#include "core/variant/variant.h" #include #include diff --git a/platform/linuxbsd/x11/detect_prime_x11.cpp b/platform/linuxbsd/x11/detect_prime_x11.cpp index 210202a6832..311c120d43d 100644 --- a/platform/linuxbsd/x11/detect_prime_x11.cpp +++ b/platform/linuxbsd/x11/detect_prime_x11.cpp @@ -33,7 +33,7 @@ #include "detect_prime_x11.h" #include "core/string/print_string.h" -#include "core/string/ustring.h" +#include "core/variant/variant.h" #include "thirdparty/glad/glad/gl.h" #include "thirdparty/glad/glad/glx.h"