perf: prefer base::SplitStringPiece()
over base::SplitString()
(#45924)
* perf: use base::SplitStringPiece() in SetNodeOptions() * perf: use base::SplitStringPiece() in StringToAccelerator() * refactor: StringToAccelerator() now takes a std::string_view
This commit is contained in:
parent
20414f66ca
commit
288ef37b1d
3 changed files with 9 additions and 8 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
@ -16,7 +17,7 @@
|
|||
|
||||
namespace accelerator_util {
|
||||
|
||||
bool StringToAccelerator(const std::string& shortcut,
|
||||
bool StringToAccelerator(const std::string_view shortcut,
|
||||
ui::Accelerator* accelerator) {
|
||||
if (!base::IsStringASCII(shortcut)) {
|
||||
LOG(ERROR) << "The accelerator string can only contain ASCII characters, "
|
||||
|
@ -26,14 +27,14 @@ bool StringToAccelerator(const std::string& shortcut,
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = base::SplitString(
|
||||
const std::vector<std::string_view> tokens = base::SplitStringPiece(
|
||||
shortcut, "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
|
||||
// Now, parse it into an accelerator.
|
||||
int modifiers = ui::EF_NONE;
|
||||
ui::KeyboardCode key = ui::VKEY_UNKNOWN;
|
||||
std::optional<char16_t> shifted_char;
|
||||
for (const auto& token : tokens) {
|
||||
for (const std::string_view token : tokens) {
|
||||
ui::KeyboardCode code = electron::KeyboardCodeFromStr(token, &shifted_char);
|
||||
if (shifted_char)
|
||||
modifiers |= ui::EF_SHIFT_DOWN;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define ELECTRON_SHELL_BROWSER_UI_ACCELERATOR_UTIL_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "shell/browser/ui/electron_menu_model.h"
|
||||
|
@ -21,7 +21,7 @@ typedef struct {
|
|||
typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
|
||||
|
||||
// Parse a string as an accelerator.
|
||||
bool StringToAccelerator(const std::string& shortcut,
|
||||
bool StringToAccelerator(std::string_view shortcut,
|
||||
ui::Accelerator* accelerator);
|
||||
|
||||
// Generate a table that contains menu model's accelerators and command ids.
|
||||
|
|
|
@ -395,14 +395,14 @@ void SetNodeOptions(base::Environment* env) {
|
|||
if (electron::fuses::IsNodeOptionsEnabled()) {
|
||||
std::string options;
|
||||
env->GetVar("NODE_OPTIONS", &options);
|
||||
std::vector<std::string> parts = base::SplitString(
|
||||
const std::vector<std::string_view> parts = base::SplitStringPiece(
|
||||
options, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
|
||||
bool is_packaged_app = electron::api::App::IsPackaged();
|
||||
|
||||
for (const auto& part : parts) {
|
||||
for (const std::string_view part : parts) {
|
||||
// Strip off values passed to individual NODE_OPTIONs
|
||||
std::string option = part.substr(0, part.find('='));
|
||||
const std::string_view option = part.substr(0, part.find('='));
|
||||
|
||||
if (is_packaged_app && !pkg_opts.contains(option)) {
|
||||
// Explicitly disallow majority of NODE_OPTIONS in packaged apps
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue