refactor: prefer inline constexpr string_view for string constants (#44405)

* refactor: BaseWindow::OnExecuteAppCommand() now takes a std::string_view

* refactor: NativeWindow::NotifyWindowExecuteAppCommand() takes a std::string_view

* refactor: AppCommandToString() returns a std::string_view, is now constexpr

* refactor: make kBrowserBackward, kBrowserForward inline constexpr std::string_view

Xref: https://abseil.io/tips/140

https://groups.google.com/a/chromium.org/g/chromium-dev/c/jROTxMo_m2Q/m/HgciN2KsAgAJ

* refactor: use inline constexpr string_view for kDevice*Key constants

Xref: https://abseil.io/tips/140

https://groups.google.com/a/chromium.org/g/chromium-dev/c/jROTxMo_m2Q/m/HgciN2KsAgAJ

* refactor: IsEnvSet now takes a base::cstring_view

* refactor: use inline constexpr cstring_view for kRunAsNode

* refactor: use inline constexpr string_view for kPDF*PluginName

* refactor: use base::FilePath::FromASCII() since "internal-pdf-viewer" is ascii

* chore: remove unused shell/common/electron_constants.cc

* fixup! refactor: IsEnvSet now takes a base::cstring_view
This commit is contained in:
Charles Kerr 2024-10-29 04:30:12 -05:00 committed by GitHub
parent cc3359f126
commit b3c2e83243
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 41 additions and 59 deletions

View file

@ -28,7 +28,7 @@ namespace electron {
namespace {
// Convert Win32 WM_APPCOMMANDS to strings.
const char* AppCommandToString(int command_id) {
constexpr std::string_view AppCommandToString(int command_id) {
switch (command_id) {
case APPCOMMAND_BROWSER_BACKWARD:
return kBrowserBackward;
@ -227,8 +227,8 @@ void NativeWindowViews::Maximize() {
}
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
std::string command = AppCommandToString(command_id);
NotifyWindowExecuteAppCommand(command);
const auto command_name = AppCommandToString(command_id);
NotifyWindowExecuteAppCommand(command_name);
return false;
}