From af3980384bf043ffaf81c82314324bfda5dfb6ff Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 23 Sep 2022 08:53:09 -0400 Subject: [PATCH] LibSQL: Return StringView from enum-to-string converters No need to allocate here. Also mark these methods as constexpr rather than inline static. --- Userland/Libraries/LibSQL/Type.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibSQL/Type.h b/Userland/Libraries/LibSQL/Type.h index fb20e42e67e..a3a79e58a64 100644 --- a/Userland/Libraries/LibSQL/Type.h +++ b/Userland/Libraries/LibSQL/Type.h @@ -8,6 +8,7 @@ #include #include +#include namespace SQL { @@ -27,13 +28,13 @@ enum class SQLType { #undef __ENUMERATE_SQL_TYPE }; -inline static String SQLType_name(SQLType t) +constexpr StringView SQLType_name(SQLType t) { switch (t) { #undef __ENUMERATE_SQL_TYPE #define __ENUMERATE_SQL_TYPE(name, cardinal, type, impl, size) \ case SQLType::type: \ - return name; + return name##sv; ENUMERATE_SQL_TYPES(__ENUMERATE_SQL_TYPE) #undef __ENUMERATE_SQL_TYPE default: @@ -41,7 +42,7 @@ inline static String SQLType_name(SQLType t) } } -inline static size_t size_of(SQLType t) +constexpr size_t size_of(SQLType t) { switch (t) { #undef __ENUMERATE_SQL_TYPE @@ -66,13 +67,13 @@ enum class Order { #undef __ENUMERATE_ORDER }; -inline static String Order_name(Order order) +constexpr StringView Order_name(Order order) { switch (order) { #undef __ENUMERATE_ORDER #define __ENUMERATE_ORDER(order) \ case Order::order: \ - return #order; + return #order##sv; ENUMERATE_ORDERS(__ENUMERATE_ORDER) #undef __ENUMERATE_ORDER default: