mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibJS: Make Token::m_message a StringView
This is only ever a string literal, so there's no need to keep creating the same strings at runtime.
This commit is contained in:
parent
51847bbebf
commit
3851d3add0
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/awesomekling
Commit: 3851d3add0
Pull-request: https://github.com/SerenityOS/serenity/pull/23690
Reviewed-by: https://github.com/Hendiadyoin1
2 changed files with 9 additions and 9 deletions
|
@ -567,7 +567,7 @@ Token Lexer::next()
|
|||
// This is being used to communicate info about invalid tokens to the parser, which then
|
||||
// can turn that into more specific error messages - instead of us having to make up a
|
||||
// bunch of Invalid* tokens (bad numeric literals, unterminated comments etc.)
|
||||
ByteString token_message;
|
||||
StringView token_message;
|
||||
|
||||
Optional<DeprecatedFlyString> identifier;
|
||||
size_t identifier_length = 0;
|
||||
|
@ -643,7 +643,7 @@ Token Lexer::next()
|
|||
m_parsed_identifiers->identifiers.set(*identifier);
|
||||
} else {
|
||||
token_type = TokenType::Invalid;
|
||||
token_message = "Start of private name '#' but not followed by valid identifier";
|
||||
token_message = "Start of private name '#' but not followed by valid identifier"sv;
|
||||
}
|
||||
} else if (auto code_point = is_identifier_start(identifier_length); code_point.has_value()) {
|
||||
bool has_escaped_character = false;
|
||||
|
@ -734,7 +734,7 @@ Token Lexer::next()
|
|||
}
|
||||
if (is_invalid_numeric_literal) {
|
||||
token_type = TokenType::Invalid;
|
||||
token_message = "Invalid numeric literal";
|
||||
token_message = "Invalid numeric literal"sv;
|
||||
}
|
||||
} else if (m_current_char == '"' || m_current_char == '\'') {
|
||||
char stop_char = m_current_char;
|
||||
|
@ -761,7 +761,7 @@ Token Lexer::next()
|
|||
} else if (m_eof) {
|
||||
if (unterminated_comment) {
|
||||
token_type = TokenType::Invalid;
|
||||
token_message = "Unterminated multi-line comment";
|
||||
token_message = "Unterminated multi-line comment"sv;
|
||||
} else {
|
||||
token_type = TokenType::Eof;
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ Token Lexer::next()
|
|||
} else {
|
||||
m_current_token = Token(
|
||||
token_type,
|
||||
String::from_byte_string(token_message).release_value_but_fixme_should_propagate_errors(),
|
||||
token_message,
|
||||
m_source.substring_view(trivia_start - 1, value_start - trivia_start),
|
||||
m_source.substring_view(value_start - 1, m_position - value_start),
|
||||
m_filename,
|
||||
|
|
|
@ -181,9 +181,9 @@ class Token {
|
|||
public:
|
||||
Token() = default;
|
||||
|
||||
Token(TokenType type, String message, StringView trivia, StringView value, StringView filename, size_t line_number, size_t line_column, size_t offset)
|
||||
Token(TokenType type, StringView message, StringView trivia, StringView value, StringView filename, size_t line_number, size_t line_column, size_t offset)
|
||||
: m_type(type)
|
||||
, m_message(move(message))
|
||||
, m_message(message)
|
||||
, m_trivia(trivia)
|
||||
, m_original_value(value)
|
||||
, m_value(value)
|
||||
|
@ -200,7 +200,7 @@ public:
|
|||
char const* name() const;
|
||||
static char const* name(TokenType);
|
||||
|
||||
String const& message() const { return m_message; }
|
||||
StringView message() const { return m_message; }
|
||||
StringView trivia() const { return m_trivia; }
|
||||
StringView original_value() const { return m_original_value; }
|
||||
StringView value() const
|
||||
|
@ -246,7 +246,7 @@ public:
|
|||
|
||||
private:
|
||||
TokenType m_type { TokenType::Invalid };
|
||||
String m_message;
|
||||
StringView m_message;
|
||||
StringView m_trivia;
|
||||
StringView m_original_value;
|
||||
Variant<Empty, StringView, DeprecatedFlyString> m_value {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue