From 3f3f45580ab7266258e97cb3cecf1e24716d61c5 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Mon, 11 Jul 2022 17:32:29 +0000 Subject: Everywhere: Add sv suffix to strings relying on StringView(char const*) Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes. --- Userland/Libraries/LibSQL/AST/Expression.cpp | 6 +++--- Userland/Libraries/LibSQL/AST/Lexer.cpp | 8 ++++---- Userland/Libraries/LibSQL/AST/Parser.cpp | 22 +++++++++++----------- Userland/Libraries/LibSQL/AST/Token.cpp | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'Userland/Libraries/LibSQL/AST') diff --git a/Userland/Libraries/LibSQL/AST/Expression.cpp b/Userland/Libraries/LibSQL/AST/Expression.cpp index b8706915f4..839b2cf235 100644 --- a/Userland/Libraries/LibSQL/AST/Expression.cpp +++ b/Userland/Libraries/LibSQL/AST/Expression.cpp @@ -12,7 +12,7 @@ namespace SQL::AST { -static constexpr StringView s_posix_basic_metacharacters = ".^$*[]+\\"; +static constexpr auto s_posix_basic_metacharacters = ".^$*[]+\\"sv; ResultOr NumericLiteral::evaluate(ExecutionContext&) const { @@ -205,7 +205,7 @@ ResultOr MatchExpression::evaluate(ExecutionContext& context) const } else if (c == '_' && !escaped) { builder.append('.'); } else if (c == '%' && !escaped) { - builder.append(".*"); + builder.append(".*"sv); } else { escaped = false; builder.append(c); @@ -226,7 +226,7 @@ ResultOr MatchExpression::evaluate(ExecutionContext& context) const auto err = regex.parser_result.error; if (err != regex::Error::NoError) { StringBuilder builder; - builder.append("Regular expression: "); + builder.append("Regular expression: "sv); builder.append(get_error_string(err)); return Result { SQLCommand::Unknown, SQLErrorCode::SyntaxError, builder.build() }; diff --git a/Userland/Libraries/LibSQL/AST/Lexer.cpp b/Userland/Libraries/LibSQL/AST/Lexer.cpp index 7a78028cb6..304d991c0e 100644 --- a/Userland/Libraries/LibSQL/AST/Lexer.cpp +++ b/Userland/Libraries/LibSQL/AST/Lexer.cpp @@ -27,16 +27,16 @@ Lexer::Lexer(StringView source) } if (s_one_char_tokens.is_empty()) { -#define __ENUMERATE_SQL_TOKEN(value, type, category) \ - if (TokenCategory::category != TokenCategory::Keyword && StringView(value).length() == 1) \ +#define __ENUMERATE_SQL_TOKEN(value, type, category) \ + if (TokenCategory::category != TokenCategory::Keyword && value##sv.length() == 1) \ s_one_char_tokens.set(value[0], TokenType::type); ENUMERATE_SQL_TOKENS #undef __ENUMERATE_SQL_TOKEN } if (s_two_char_tokens.is_empty()) { -#define __ENUMERATE_SQL_TOKEN(value, type, category) \ - if (TokenCategory::category != TokenCategory::Keyword && StringView(value).length() == 2) \ +#define __ENUMERATE_SQL_TOKEN(value, type, category) \ + if (TokenCategory::category != TokenCategory::Keyword && value##sv.length() == 2) \ s_two_char_tokens.set(value, TokenType::type); ENUMERATE_SQL_TOKENS #undef __ENUMERATE_SQL_TOKEN diff --git a/Userland/Libraries/LibSQL/AST/Parser.cpp b/Userland/Libraries/LibSQL/AST/Parser.cpp index 94ed6f55e3..3f18b34fe4 100644 --- a/Userland/Libraries/LibSQL/AST/Parser.cpp +++ b/Userland/Libraries/LibSQL/AST/Parser.cpp @@ -58,7 +58,7 @@ NonnullRefPtr Parser::parse_statement() case TokenType::Select: return parse_select_statement({}); default: - expected("CREATE, ALTER, DROP, DESCRIBE, INSERT, UPDATE, DELETE, or SELECT"); + expected("CREATE, ALTER, DROP, DESCRIBE, INSERT, UPDATE, DELETE, or SELECT"sv); return create_ast_node(); } } @@ -75,7 +75,7 @@ NonnullRefPtr Parser::parse_statement_with_expression_list(RefPtr(); } } @@ -226,7 +226,7 @@ NonnullRefPtr Parser::parse_insert_statement(RefPtr(chained_expression.release_nonnull())); } } else { - expected("Chained expression"); + expected("Chained expression"sv); } }); } else if (match(TokenType::Select)) { @@ -381,7 +381,7 @@ RefPtr Parser::parse_common_table_expression_list() parse_comma_separated_list(false, [&]() { common_table_expression.append(parse_common_table_expression()); }); if (common_table_expression.is_empty()) { - expected("Common table expression list"); + expected("Common table expression list"sv); return {}; } @@ -432,7 +432,7 @@ NonnullRefPtr Parser::parse_primary_expression() if (auto expression = parse_exists_expression(false)) return expression.release_nonnull(); - expected("Primary Expression"); + expected("Primary Expression"sv); consume(); return create_ast_node(); @@ -465,7 +465,7 @@ NonnullRefPtr Parser::parse_secondary_expression(NonnullRefPtr(); @@ -805,13 +805,13 @@ RefPtr Parser::parse_between_expression(NonnullRefPtr ex auto nested = parse_expression(); if (!is(*nested)) { - expected("Binary Expression"); + expected("Binary Expression"sv); return create_ast_node(); } auto const& binary_expression = static_cast(*nested); if (binary_expression.type() != BinaryOperator::And) { - expected("AND Expression"); + expected("AND Expression"sv); return create_ast_node(); } @@ -903,7 +903,7 @@ NonnullRefPtr Parser::parse_signed_number() return create_ast_node(is_positive ? number : (number * -1)); } - expected("NumericLiteral"); + expected("NumericLiteral"sv); return create_ast_node(0); } @@ -1047,7 +1047,7 @@ NonnullRefPtr Parser::parse_ordering_term() else if (consume_if(TokenType::Last)) nulls = Nulls::Last; else - expected("FIRST or LAST"); + expected("FIRST or LAST"sv); } return create_ast_node(move(expression), move(collation_name), order, nulls); @@ -1080,7 +1080,7 @@ ConflictResolution Parser::parse_conflict_resolution() if (consume_if(TokenType::Rollback)) return ConflictResolution::Rollback; - expected("ABORT, FAIL, IGNORE, REPLACE, or ROLLBACK"); + expected("ABORT, FAIL, IGNORE, REPLACE, or ROLLBACK"sv); } return ConflictResolution::Abort; diff --git a/Userland/Libraries/LibSQL/AST/Token.cpp b/Userland/Libraries/LibSQL/AST/Token.cpp index 9acd3370de..0e33bd5dd0 100644 --- a/Userland/Libraries/LibSQL/AST/Token.cpp +++ b/Userland/Libraries/LibSQL/AST/Token.cpp @@ -16,7 +16,7 @@ StringView Token::name(TokenType type) switch (type) { #define __ENUMERATE_SQL_TOKEN(value, type, category) \ case TokenType::type: \ - return #type; + return #type##sv; ENUMERATE_SQL_TOKENS #undef __ENUMERATE_SQL_TOKEN default: -- cgit v1.2.3