Skip to content

Commit

Permalink
Merge pull request #15741 from ethereum/dont-copy-current-literal-in-…
Browse files Browse the repository at this point in the history
…parser-base

ParserBase: avoid copying around currentLiteral
  • Loading branch information
clonker authored Jan 29, 2025
2 parents 4d6f71a + 5389915 commit dcca9d7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion liblangutil/ParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Token ParserBase::peekNextToken() const
return m_scanner->peekNextToken();
}

std::string ParserBase::currentLiteral() const
std::string_view ParserBase::currentLiteral() const
{
return m_scanner->currentLiteral();
}
Expand Down
3 changes: 2 additions & 1 deletion liblangutil/ParserBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class ParserBase
Token currentToken() const;
Token peekNextToken() const;
std::string tokenName(Token _token);
std::string currentLiteral() const;
/// Points to the current literal. The string view invalidates when the parser advances.
std::string_view currentLiteral() const;
virtual Token advance();
///@}

Expand Down
2 changes: 1 addition & 1 deletion libsolutil/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ inline std::string asString(bytesConstRef _b)
}

/// Converts a string to a byte array containing the string's (byte) data.
inline bytes asBytes(std::string const& _b)
inline bytes asBytes(std::string_view const _b)
{
return bytes((uint8_t const*)_b.data(), (uint8_t const*)(_b.data() + _b.size()));
}
Expand Down
4 changes: 2 additions & 2 deletions libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void Parser::checkBreakContinuePosition(std::string const& _which)
}
}

bool Parser::isValidNumberLiteral(std::string const& _literal)
bool Parser::isValidNumberLiteral(std::string_view const _literal)
{
try
{
Expand All @@ -799,7 +799,7 @@ bool Parser::isValidNumberLiteral(std::string const& _literal)
if (boost::starts_with(_literal, "0x"))
return true;
else
return _literal.find_first_not_of("0123456789") == std::string::npos;
return _literal.find_first_not_of("0123456789") == std::string_view::npos;
}

void Parser::raiseUnsupportedTypesError(SourceLocation const& _location) const
Expand Down
2 changes: 1 addition & 1 deletion libyul/AsmParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Parser: public langutil::ParserBase
/// Reports an error if we are currently not inside the body part of a for loop.
void checkBreakContinuePosition(std::string const& _which);

static bool isValidNumberLiteral(std::string const& _literal);
static bool isValidNumberLiteral(std::string_view _literal);

private:
Dialect const& m_dialect;
Expand Down
2 changes: 1 addition & 1 deletion libyul/ObjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void ObjectParser::parseData(Object& _containingObject)
std::string ObjectParser::parseUniqueName(Object const* _containingObject)
{
expectToken(Token::StringLiteral, false);
auto const name = currentLiteral();
std::string const name{currentLiteral()};
if (name.empty())
parserError(3287_error, "Object name cannot be empty.");
else if (_containingObject && _containingObject->name == name)
Expand Down

0 comments on commit dcca9d7

Please sign in to comment.