From 6d65d7d08bfc4f2b08f48825fdb7889330ba3951 Mon Sep 17 00:00:00 2001 From: Elliot Goodrich Date: Thu, 21 Nov 2024 06:15:16 +0000 Subject: [PATCH] Small tidy of `std::pair` creation Make it very obvious to the compiler that we don't need a conditional here and that we can construct the `std::pair` directly. Based on profiling, MSVC is struggling with this and is causing a ~1% overhead. --- src/evalstring.cpp | 5 ++--- src/evalstring.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/evalstring.cpp b/src/evalstring.cpp index 21d318c..30d773f 100644 --- a/src/evalstring.cpp +++ b/src/evalstring.cpp @@ -73,9 +73,8 @@ std::pair EvalString::const_iterator::operator*() const { Offset length; std::copy_n(m_pos, sizeof(length), reinterpret_cast(&length)); - return std::make_pair( - std::string_view{m_pos + sizeof(length), clearLeadingBit(length)}, - hasLeadingBit(length) ? TokenType::Variable : TokenType::Text); + return {{m_pos + sizeof(length), clearLeadingBit(length)}, + static_cast(hasLeadingBit(length))}; } EvalString::const_iterator& EvalString::const_iterator::operator++() { diff --git a/src/evalstring.h b/src/evalstring.h index 494e2b6..cd70ad7 100644 --- a/src/evalstring.h +++ b/src/evalstring.h @@ -50,8 +50,8 @@ class EvalString { * @brief Enum to represent the type of token. */ enum class TokenType { - Text, ///< Represents a text token. - Variable ///< Represents a variable token. + Text = 0, ///< Represents a text token. + Variable = 1, ///< Represents a variable token. }; /**