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:
parent
fa6d14c22d
commit
ab49e98401
7 changed files with 44 additions and 40 deletions
|
@ -169,7 +169,7 @@ base::Time ParseTimeProperty(const absl::optional<double>& value) {
|
|||
return base::Time::FromDoubleT(*value);
|
||||
}
|
||||
|
||||
std::string InclusionStatusToString(net::CookieInclusionStatus status) {
|
||||
base::StringPiece InclusionStatusToString(net::CookieInclusionStatus status) {
|
||||
if (status.HasExclusionReason(net::CookieInclusionStatus::EXCLUDE_HTTP_ONLY))
|
||||
return "Failed to create httponly cookie";
|
||||
if (status.HasExclusionReason(
|
||||
|
|
|
@ -167,7 +167,7 @@ const char* const kBuiltinSchemes[] = {
|
|||
};
|
||||
|
||||
// Convert error code to string.
|
||||
std::string ErrorCodeToString(ProtocolError error) {
|
||||
constexpr base::StringPiece ErrorCodeToString(ProtocolError error) {
|
||||
switch (error) {
|
||||
case ProtocolError::kRegistered:
|
||||
return "The scheme has been registered";
|
||||
|
|
|
@ -25,33 +25,36 @@ namespace electron::api {
|
|||
|
||||
namespace {
|
||||
|
||||
std::string MessageSourceToString(
|
||||
constexpr base::StringPiece MessageSourceToString(
|
||||
const blink::mojom::ConsoleMessageSource source) {
|
||||
if (source == blink::mojom::ConsoleMessageSource::kXml)
|
||||
switch (source) {
|
||||
case blink::mojom::ConsoleMessageSource::kXml:
|
||||
return "xml";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kJavaScript)
|
||||
case blink::mojom::ConsoleMessageSource::kJavaScript:
|
||||
return "javascript";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kNetwork)
|
||||
case blink::mojom::ConsoleMessageSource::kNetwork:
|
||||
return "network";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kConsoleApi)
|
||||
case blink::mojom::ConsoleMessageSource::kConsoleApi:
|
||||
return "console-api";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kStorage)
|
||||
case blink::mojom::ConsoleMessageSource::kStorage:
|
||||
return "storage";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kRendering)
|
||||
case blink::mojom::ConsoleMessageSource::kRendering:
|
||||
return "rendering";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kSecurity)
|
||||
case blink::mojom::ConsoleMessageSource::kSecurity:
|
||||
return "security";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kDeprecation)
|
||||
case blink::mojom::ConsoleMessageSource::kDeprecation:
|
||||
return "deprecation";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kWorker)
|
||||
case blink::mojom::ConsoleMessageSource::kWorker:
|
||||
return "worker";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kViolation)
|
||||
case blink::mojom::ConsoleMessageSource::kViolation:
|
||||
return "violation";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kIntervention)
|
||||
case blink::mojom::ConsoleMessageSource::kIntervention:
|
||||
return "intervention";
|
||||
if (source == blink::mojom::ConsoleMessageSource::kRecommendation)
|
||||
case blink::mojom::ConsoleMessageSource::kRecommendation:
|
||||
return "recommendation";
|
||||
default:
|
||||
return "other";
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> ServiceWorkerRunningInfoToDict(
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
namespace {
|
||||
|
||||
std::string MediaStreamTypeToString(blink::mojom::MediaStreamType type) {
|
||||
constexpr base::StringPiece MediaStreamTypeToString(
|
||||
blink::mojom::MediaStreamType type) {
|
||||
switch (type) {
|
||||
case blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE:
|
||||
return "audio";
|
||||
|
|
|
@ -180,9 +180,9 @@ struct Converter<blink::WebInputEvent::Modifiers> {
|
|||
}
|
||||
};
|
||||
|
||||
std::vector<std::string> ModifiersToArray(int modifiers) {
|
||||
std::vector<base::StringPiece> ModifiersToArray(int modifiers) {
|
||||
using Modifiers = blink::WebInputEvent::Modifiers;
|
||||
std::vector<std::string> modifier_strings;
|
||||
std::vector<base::StringPiece> modifier_strings;
|
||||
if (modifiers & Modifiers::kShiftKey)
|
||||
modifier_strings.push_back("shift");
|
||||
if (modifiers & Modifiers::kControlKey)
|
||||
|
|
|
@ -383,7 +383,7 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
|||
|
||||
private:
|
||||
bool MaybeGetRenderFrame(v8::Isolate* isolate,
|
||||
const std::string& method_name,
|
||||
const base::StringPiece method_name,
|
||||
content::RenderFrame** render_frame_ptr) {
|
||||
std::string error_msg;
|
||||
if (!MaybeGetRenderFrame(&error_msg, method_name, render_frame_ptr)) {
|
||||
|
@ -394,13 +394,12 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
|||
}
|
||||
|
||||
bool MaybeGetRenderFrame(std::string* error_msg,
|
||||
const std::string& method_name,
|
||||
const base::StringPiece method_name,
|
||||
content::RenderFrame** render_frame_ptr) {
|
||||
auto* frame = render_frame();
|
||||
if (!frame) {
|
||||
*error_msg = "Render frame was torn down before webFrame." + method_name +
|
||||
" could be "
|
||||
"executed";
|
||||
*error_msg = base::ToString("Render frame was torn down before webFrame.",
|
||||
method_name, " could be executed");
|
||||
return false;
|
||||
}
|
||||
*render_frame_ptr = frame;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue