From 3d656ba6001ec63156a75d3031dbe98eb1938be5 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Mon, 11 Jul 2022 20:47:05 +0000 Subject: [PATCH] LibJS: Emit StringViews for ErrorType instances This removes the need for calculating each string's length during ErrorType use at the cost of storing it within the binary. --- Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp | 2 +- Userland/Libraries/LibJS/Runtime/ErrorTypes.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp b/Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp index 85f9302952..2eb5e7654b 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.cpp @@ -9,7 +9,7 @@ namespace JS { #define __ENUMERATE_JS_ERROR(name, message) \ - const ErrorType ErrorType::name = ErrorType(message); + const ErrorType ErrorType::name = ErrorType(message##sv); JS_ENUMERATE_ERROR_TYPES(__ENUMERATE_JS_ERROR) #undef __ENUMERATE_JS_ERROR diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index f97f323626..0cf24d2edb 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -6,6 +6,8 @@ #pragma once +#include + #define JS_ENUMERATE_ERROR_TYPES(M) \ M(ArrayMaxSize, "Maximum array size exceeded") \ M(AccessorBadField, "Accessor descriptor's '{}' field must be a function or undefined") \ @@ -306,18 +308,18 @@ public: JS_ENUMERATE_ERROR_TYPES(__ENUMERATE_JS_ERROR) #undef __ENUMERATE_JS_ERROR - char const* message() const + StringView message() const { return m_message; } private: - explicit ErrorType(char const* message) + explicit ErrorType(StringView message) : m_message(message) { } - char const* m_message; + StringView m_message; }; }