1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:57:35 +00:00

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.
This commit is contained in:
sin-ack 2022-07-11 17:32:29 +00:00 committed by Andreas Kling
parent e5f09ea170
commit 3f3f45580a
762 changed files with 8315 additions and 8316 deletions

View file

@ -155,7 +155,7 @@ static double parse_date_string(String const& date_string)
// Date.parse() is allowed to accept an arbitrary number of implementation-defined formats.
// Parse formats of this type: "Wed Apr 17 23:08:53 +0000 2019"
auto maybe_datetime = Core::DateTime::parse("%a %b %e %T %z %Y", date_string);
auto maybe_datetime = Core::DateTime::parse("%a %b %e %T %z %Y"sv, date_string);
if (maybe_datetime.has_value())
return 1000.0 * maybe_datetime->timestamp();

View file

@ -20,7 +20,7 @@ struct Variable {
#define JS_ENVIRONMENT(class_, base_class) \
public: \
using Base = base_class; \
virtual StringView class_name() const override { return #class_; }
virtual StringView class_name() const override { return #class_##sv; }
class Environment : public Cell {
public:

View file

@ -299,7 +299,7 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(GlobalObject& g
// here, but at some point we should split the the NumberFormat exporter to export both formats of the data.
static String convert_number_format_pattern_to_duration_format_template(Unicode::NumberFormat const& number_format)
{
auto result = number_format.zero_format.replace("{number}", "{0}", ReplaceMode::FirstOnly);
auto result = number_format.zero_format.replace("{number}"sv, "{0}"sv, ReplaceMode::FirstOnly);
for (size_t i = 0; i < number_format.identifiers.size(); ++i)
result = result.replace(String::formatted("{{unitIdentifier:{}}}", i), number_format.identifiers[i], ReplaceMode::FirstOnly);
@ -428,7 +428,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(Gl
auto separator = Unicode::get_number_system_symbol(data_locale, duration_format.numbering_system(), Unicode::NumericSymbol::TimeSeparator).value_or(":"sv);
// 2. Append the new Record { [[Type]]: "literal", [[Value]]: separator} to the end of result.
result.append({ "literal", separator });
result.append({ "literal"sv, separator });
}
}

View file

@ -254,7 +254,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_object(GlobalObject& global
}
StringBuilder builder;
if (property_strings.is_empty()) {
builder.append("{}");
builder.append("{}"sv);
} else {
bool first = true;
builder.append('{');
@ -306,7 +306,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_array(GlobalObject& global_
for (size_t i = 0; i < length; ++i) {
auto serialized_property_string = TRY(serialize_json_property(global_object, state, i, &object));
if (serialized_property_string.is_null()) {
property_strings.append("null");
property_strings.append("null"sv);
} else {
property_strings.append(serialized_property_string);
}
@ -314,7 +314,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_array(GlobalObject& global_
StringBuilder builder;
if (property_strings.is_empty()) {
builder.append("[]");
builder.append("[]"sv);
} else {
if (state.gap.is_empty()) {
builder.append('[');
@ -327,7 +327,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_array(GlobalObject& global_
}
builder.append(']');
} else {
builder.append("[\n");
builder.append("[\n"sv);
builder.append(state.indent);
auto separator = String::formatted(",\n{}", state.indent);
bool first = true;
@ -357,25 +357,25 @@ String JSONObject::quote_json_string(String string)
for (auto code_point : utf_view) {
switch (code_point) {
case '\b':
builder.append("\\b");
builder.append("\\b"sv);
break;
case '\t':
builder.append("\\t");
builder.append("\\t"sv);
break;
case '\n':
builder.append("\\n");
builder.append("\\n"sv);
break;
case '\f':
builder.append("\\f");
builder.append("\\f"sv);
break;
case '\r':
builder.append("\\r");
builder.append("\\r"sv);
break;
case '"':
builder.append("\\\"");
builder.append("\\\""sv);
break;
case '\\':
builder.append("\\\\");
builder.append("\\\\"sv);
break;
default:
if (code_point < 0x20 || Utf16View::is_high_surrogate(code_point) || Utf16View::is_low_surrogate(code_point)) {

View file

@ -30,7 +30,7 @@ public: \
using Base = base_class; \
virtual StringView class_name() const override \
{ \
return #class_; \
return #class_##sv; \
}
struct PrivateElement {

View file

@ -81,7 +81,7 @@ struct Formatter<JS::PropertyAttributes> : Formatter<StringView> {
parts.append(String::formatted("[[Writable]]: {}", property_attributes.is_writable()));
parts.append(String::formatted("[[Enumerable]]: {}", property_attributes.is_enumerable()));
parts.append(String::formatted("[[Configurable]]: {}", property_attributes.is_configurable()));
return Formatter<StringView>::format(builder, String::formatted("PropertyAttributes {{ {} }}", String::join(", ", parts)));
return Formatter<StringView>::format(builder, String::formatted("PropertyAttributes {{ {} }}", String::join(", "sv, parts)));
}
};

View file

@ -62,7 +62,7 @@ struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
parts.append(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable));
if (property_descriptor.configurable.has_value())
parts.append(String::formatted("[[Configurable]]: {}", *property_descriptor.configurable));
return Formatter<StringView>::format(builder, String::formatted("PropertyDescriptor {{ {} }}", String::join(", ", parts)));
return Formatter<StringView>::format(builder, String::formatted("PropertyDescriptor {{ {} }}", String::join(", "sv, parts)));
}
};

View file

@ -199,24 +199,24 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
String Reference::to_string() const
{
StringBuilder builder;
builder.append("Reference { Base=");
builder.append("Reference { Base="sv);
switch (m_base_type) {
case BaseType::Unresolvable:
builder.append("Unresolvable");
builder.append("Unresolvable"sv);
break;
case BaseType::Environment:
builder.appendff("{}", base_environment().class_name());
break;
case BaseType::Value:
if (m_base_value.is_empty())
builder.append("<empty>");
builder.append("<empty>"sv);
else
builder.appendff("{}", m_base_value.to_string_without_side_effects());
break;
}
builder.append(", ReferencedName=");
builder.append(", ReferencedName="sv);
if (!m_name.is_valid())
builder.append("<invalid>");
builder.append("<invalid>"sv);
else if (m_name.is_symbol())
builder.appendff("{}", m_name.as_symbol()->to_string());
else
@ -224,11 +224,11 @@ String Reference::to_string() const
builder.appendff(", Strict={}", m_strict);
builder.appendff(", ThisValue=");
if (m_this_value.is_empty())
builder.append("<empty>");
builder.append("<empty>"sv);
else
builder.appendff("{}", m_this_value.to_string_without_side_effects());
builder.append(" }");
builder.append(" }"sv);
return builder.to_string();
}

View file

@ -182,7 +182,7 @@ String RegExpObject::escape_regexp_pattern() const
if (m_pattern.is_empty())
return "(?:)";
// FIXME: Check u flag and escape accordingly
return m_pattern.replace("\n", "\\n", ReplaceMode::All).replace("\r", "\\r", ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\\u2028", ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029", ReplaceMode::All).replace("/", "\\/", ReplaceMode::All);
return m_pattern.replace("\n"sv, "\\n"sv, ReplaceMode::All).replace("\r"sv, "\\r"sv, ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\\u2028"sv, ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029"sv, ReplaceMode::All).replace("/"sv, "\\/"sv, ReplaceMode::All);
}
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate

View file

@ -474,7 +474,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags)
#define __JS_ENUMERATE(flagName, flag_name, flag_char) \
auto flag_##flag_name = TRY(regexp_object->get(vm.names.flagName)); \
if (flag_##flag_name.to_boolean()) \
builder.append(#flag_char);
builder.append(#flag_char##sv);
JS_ENUMERATE_REGEXP_FLAGS
#undef __JS_ENUMERATE

View file

@ -969,13 +969,13 @@ static ThrowCompletionOr<Value> create_html(GlobalObject& global_object, Value s
auto value_string = TRY(value.to_string(global_object));
builder.append(' ');
builder.append(attribute);
builder.append("=\"");
builder.append(value_string.replace("\"", "&quot;", ReplaceMode::All));
builder.append("=\""sv);
builder.append(value_string.replace("\""sv, "&quot;"sv, ReplaceMode::All));
builder.append('"');
}
builder.append('>');
builder.append(str);
builder.append("</");
builder.append("</"sv);
builder.append(tag);
builder.append('>');
return js_string(vm, builder.build());

View file

@ -449,7 +449,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
: TypedArray(prototype, \
reinterpret_cast<TypedArrayBase::IntrinsicConstructor>(&GlobalObject::snake_name##_constructor), length, array_buffer) \
{ \
if constexpr (StringView { #ClassName }.is_one_of("BigInt64Array", "BigUint64Array")) \
if constexpr (#ClassName##sv.is_one_of("BigInt64Array", "BigUint64Array")) \
m_content_type = ContentType::BigInt; \
else \
m_content_type = ContentType::Number; \

View file

@ -599,7 +599,7 @@ String VM::join_arguments(size_t start_index) const
{
StringBuilder joined_arguments;
for (size_t i = start_index; i < argument_count(); ++i) {
joined_arguments.append(argument(i).to_string_without_side_effects().characters());
joined_arguments.append(argument(i).to_string_without_side_effects().view());
if (i != argument_count() - 1)
joined_arguments.append(' ');
}

View file

@ -156,7 +156,7 @@ static String double_to_string(double d)
return builder.to_string();
}
if (-6 < exponent && exponent <= 0) {
builder.append("0.");
builder.append("0."sv);
builder.append(String::repeated('0', -exponent));
builder.append(digits);
return builder.to_string();