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

Meta+Userland: Simplify some formatters

These are mostly minor mistakes I've encountered while working on the
removal of StringView(char const*). The usage of builder.put_string over
Format<FormatString>::format is preferrable as it will avoid the
indirection altogether when there's no formatting to be done. Similarly,
there is no need to do format(builder, "{}", number) when
builder.put_u64(number) works equally well.

Additionally a few Strings where only constant strings were used are
replaced with StringViews.
This commit is contained in:
sin-ack 2022-07-11 20:23:24 +00:00 committed by Andreas Kling
parent 7da00bfa8d
commit 7456904a39
9 changed files with 64 additions and 67 deletions

View file

@ -70,8 +70,7 @@ struct AK::Formatter<JS::Cell> : AK::Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, JS::Cell const* cell)
{
if (!cell)
return Formatter<FormatString>::format(builder, "Cell{nullptr}");
else
return Formatter<FormatString>::format(builder, "{}({})", cell->class_name(), cell);
return builder.put_string("Cell{nullptr}"sv);
return Formatter<FormatString>::format(builder, "{}({})"sv, cell->class_name(), cell);
}
};

View file

@ -228,10 +228,10 @@ struct Formatter<JS::PropertyKey> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, JS::PropertyKey const& property_key)
{
if (!property_key.is_valid())
return Formatter<StringView>::format(builder, "<invalid PropertyKey>");
return builder.put_string("<invalid PropertyKey>"sv);
if (property_key.is_number())
return Formatter<StringView>::format(builder, String::number(property_key.as_number()));
return Formatter<StringView>::format(builder, property_key.to_string_or_symbol().to_display_string());
return builder.put_u64(property_key.as_number());
return builder.put_string(property_key.to_string_or_symbol().to_display_string());
}
};