Skip to content

Commit 5389915

Browse files
committed
ParserBase: avoid copying around currentLiteral
1 parent 9412165 commit 5389915

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

liblangutil/ParserBase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Token ParserBase::peekNextToken() const
4343
return m_scanner->peekNextToken();
4444
}
4545

46-
std::string ParserBase::currentLiteral() const
46+
std::string_view ParserBase::currentLiteral() const
4747
{
4848
return m_scanner->currentLiteral();
4949
}

liblangutil/ParserBase.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class ParserBase
7171
Token currentToken() const;
7272
Token peekNextToken() const;
7373
std::string tokenName(Token _token);
74-
std::string currentLiteral() const;
74+
/// Points to the current literal. The string view invalidates when the parser advances.
75+
std::string_view currentLiteral() const;
7576
virtual Token advance();
7677
///@}
7778

libsolutil/CommonData.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ inline std::string asString(bytesConstRef _b)
470470
}
471471

472472
/// Converts a string to a byte array containing the string's (byte) data.
473-
inline bytes asBytes(std::string const& _b)
473+
inline bytes asBytes(std::string_view const _b)
474474
{
475475
return bytes((uint8_t const*)_b.data(), (uint8_t const*)(_b.data() + _b.size()));
476476
}

libyul/AsmParser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ void Parser::checkBreakContinuePosition(std::string const& _which)
779779
}
780780
}
781781

782-
bool Parser::isValidNumberLiteral(std::string const& _literal)
782+
bool Parser::isValidNumberLiteral(std::string_view const _literal)
783783
{
784784
try
785785
{
@@ -793,7 +793,7 @@ bool Parser::isValidNumberLiteral(std::string const& _literal)
793793
if (boost::starts_with(_literal, "0x"))
794794
return true;
795795
else
796-
return _literal.find_first_not_of("0123456789") == std::string::npos;
796+
return _literal.find_first_not_of("0123456789") == std::string_view::npos;
797797
}
798798

799799
void Parser::raiseUnsupportedTypesError(SourceLocation const& _location) const

libyul/AsmParser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Parser: public langutil::ParserBase
152152
/// Reports an error if we are currently not inside the body part of a for loop.
153153
void checkBreakContinuePosition(std::string const& _which);
154154

155-
static bool isValidNumberLiteral(std::string const& _literal);
155+
static bool isValidNumberLiteral(std::string_view _literal);
156156

157157
private:
158158
Dialect const& m_dialect;

libyul/ObjectParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void ObjectParser::parseData(Object& _containingObject)
198198
std::string ObjectParser::parseUniqueName(Object const* _containingObject)
199199
{
200200
expectToken(Token::StringLiteral, false);
201-
auto const name = currentLiteral();
201+
std::string const name{currentLiteral()};
202202
if (name.empty())
203203
parserError(3287_error, "Object name cannot be empty.");
204204
else if (_containingObject && _containingObject->name == name)

0 commit comments

Comments
 (0)