Mark literal string creation as constexpr

* The compiler doesn't seem to do much with this in debug, but it might help in
  release.
This commit is contained in:
baldurk
2022-02-15 15:29:47 +00:00
parent da979b23bc
commit 435ed5ad38
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -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);
}
+2 -2
View File
@@ -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<const type &, decltype(el)>::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<const type &, decltype(el)>::value, \
"Type in macro doesn't match el"); \
uint64_t local = (uint64_t)el; \