LibSQL: Return StringView from enum-to-string converters

No need to allocate here. Also mark these methods as constexpr rather
than inline static.
This commit is contained in:
Timothy Flynn 2022-09-23 08:53:09 -04:00 committed by Ali Mohammad Pur
parent c0b54f18b5
commit af3980384b
Notes: sideshowbarker 2024-07-17 05:48:34 +09:00

View file

@ -8,6 +8,7 @@
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/StringView.h>
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: