perf: prefer base::StringPiece over std::string for build-time strings (#38717)

* perf: use base::StringPiece in InclusionStatusToString()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in ErrorCodeToString()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in MessageSourceToString()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in CursorTypeToString()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in MediaStreamTypeToString()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in ModifiersToArray()

The strings are all build-time constants and this is a private function

* perf: use base::StringPiece in WebFrameRenderer::MaybeGetRenderFrame()

The strings are all build-time constants and this is a private function
This commit is contained in:
Charles Kerr 2023-06-12 02:55:22 -05:00 committed by GitHub
parent fa6d14c22d
commit ab49e98401
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 40 deletions

View file

@ -379,8 +379,9 @@ namespace electron::api {
namespace {
std::string CursorTypeToString(const ui::Cursor& cursor) {
switch (cursor.type()) {
constexpr base::StringPiece CursorTypeToString(
ui::mojom::CursorType cursor_type) {
switch (cursor_type) {
case ui::mojom::CursorType::kPointer:
return "pointer";
case ui::mojom::CursorType::kCross:
@ -3500,14 +3501,14 @@ bool WebContents::IsBeingCaptured() {
void WebContents::OnCursorChanged(const ui::Cursor& cursor) {
if (cursor.type() == ui::mojom::CursorType::kCustom) {
Emit("cursor-changed", CursorTypeToString(cursor),
Emit("cursor-changed", CursorTypeToString(cursor.type()),
gfx::Image::CreateFrom1xBitmap(cursor.custom_bitmap()),
cursor.image_scale_factor(),
gfx::Size(cursor.custom_bitmap().width(),
cursor.custom_bitmap().height()),
cursor.custom_hotspot());
} else {
Emit("cursor-changed", CursorTypeToString(cursor));
Emit("cursor-changed", CursorTypeToString(cursor.type()));
}
}