Skip to content

Commit

Permalink
Small tidy of std::pair creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elliotgoodrich committed Nov 21, 2024
1 parent 7f3c495 commit 6d65d7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/evalstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ std::pair<std::string_view, EvalString::TokenType>
EvalString::const_iterator::operator*() const {
Offset length;
std::copy_n(m_pos, sizeof(length), reinterpret_cast<char*>(&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<TokenType>(hasLeadingBit(length))};
}

EvalString::const_iterator& EvalString::const_iterator::operator++() {
Expand Down
4 changes: 2 additions & 2 deletions src/evalstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};

/**
Expand Down

0 comments on commit 6d65d7d

Please sign in to comment.