From 435ed5ad38930cd167f25289959007ca1db898c3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 15 Feb 2022 15:29:47 +0000 Subject: [PATCH] Mark literal string creation as constexpr * The compiler doesn't seem to do much with this in debug, but it might help in release. --- renderdoc/api/replay/rdcstr.h | 6 +++--- renderdoc/api/replay/stringise.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/renderdoc/api/replay/rdcstr.h b/renderdoc/api/replay/rdcstr.h index 624e17827..4b9965427 100644 --- a/renderdoc/api/replay/rdcstr.h +++ b/renderdoc/api/replay/rdcstr.h @@ -42,12 +42,12 @@ class rdcliteral size_t len; // make the literal operator a friend so it can construct fixed strings. No-one else can. - friend rdcliteral operator"" _lit(const char *str, size_t len); + friend constexpr rdcliteral operator"" _lit(const char *str, size_t len); // similarly friend inflexible strings to allow them to decompose to a literal friend class rdcinflexiblestr; - rdcliteral(const char *s, size_t l) : str(s), len(l) {} + constexpr rdcliteral(const char *s, size_t l) : str(s), len(l) {} rdcliteral() = delete; public: @@ -57,7 +57,7 @@ public: const char *end() const { return str + len; } }; -inline rdcliteral operator"" _lit(const char *str, size_t len) +inline constexpr rdcliteral operator"" _lit(const char *str, size_t len) { return rdcliteral(str, len); } diff --git a/renderdoc/api/replay/stringise.h b/renderdoc/api/replay/stringise.h index 30b99db98..411689c80 100644 --- a/renderdoc/api/replay/stringise.h +++ b/renderdoc/api/replay/stringise.h @@ -52,7 +52,7 @@ rdcstr ToStr(const T &el) #define BEGIN_ENUM_STRINGISE(type) \ using enumType = type; \ static const char unknown_prefix[] = #type "("; \ - static rdcliteral empty_ret = STRING_LITERAL(#type "(0)"); \ + constexpr rdcliteral empty_ret = STRING_LITERAL(#type "(0)"); \ static_assert(std::is_same::value, \ "Type in macro doesn't match el"); \ (void)(enumType) el; \ @@ -85,7 +85,7 @@ rdcstr ToStr(const T &el) #define BEGIN_BITFIELD_STRINGISE(type) \ using enumType = type; \ static const char unknown_prefix[] = " | " #type "("; \ - static rdcliteral empty_ret = STRING_LITERAL(#type "(0)"); \ + constexpr rdcliteral empty_ret = STRING_LITERAL(#type "(0)"); \ static_assert(std::is_same::value, \ "Type in macro doesn't match el"); \ uint64_t local = (uint64_t)el; \