mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
c0b54f18b5
commit
af3980384b
Notes:
sideshowbarker
2024-07-17 05:48:34 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/af3980384b Pull-request: https://github.com/SerenityOS/serenity/pull/15312 Reviewed-by: https://github.com/alimpfard
1 changed files with 6 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue