From f4e709c47e72c8dc89ec137b628e5924ee36ba30 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 10:58:45 +0200 Subject: [PATCH] refactor: avoid a few unnecessary strings (#47654) * perf: replace string temporary with string_view in GetXdgAppId() Co-authored-by: Charles Kerr * perf: replace string temporary with string_view in ToV8(WindowOpenDisposition) Co-authored-by: Charles Kerr * perf: replace string temporary with string_view in ToV8(electron::api::WebContents::Type) Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/api/electron_api_web_contents.cc | 4 ++-- shell/common/platform_util_linux.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index d25171ea116f..e062b7a1aff8 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -242,7 +242,7 @@ template <> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, WindowOpenDisposition val) { - std::string disposition = "other"; + std::string_view disposition = "other"; switch (val) { case WindowOpenDisposition::CURRENT_TAB: disposition = "default"; @@ -303,7 +303,7 @@ struct Converter { static v8::Local ToV8(v8::Isolate* isolate, electron::api::WebContents::Type val) { using Type = electron::api::WebContents::Type; - std::string type; + std::string_view type; switch (val) { case Type::kBackgroundPage: type = "backgroundPage"; diff --git a/shell/common/platform_util_linux.cc b/shell/common/platform_util_linux.cc index dea72f7a370b..87c3d6fbda33 100644 --- a/shell/common/platform_util_linux.cc +++ b/shell/common/platform_util_linux.cc @@ -430,7 +430,7 @@ std::optional GetDesktopName() { std::string GetXdgAppId() { if (std::optional desktop_file_name = GetDesktopName()) { - const std::string kDesktopExtension{".desktop"}; + constexpr std::string_view kDesktopExtension = ".desktop"; if (base::EndsWith(*desktop_file_name, kDesktopExtension, base::CompareCase::INSENSITIVE_ASCII)) { desktop_file_name->resize(desktop_file_name->size() -