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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue