refactor: more constexpr lookup tables (#38886)
* refactor: use constexpr lookup table in electron_api_web_contents.cc * refactor: make KeyboardCodeFromStr() private it is only used as a helper to KeyboardCodeFromStr() * chore: savepoint * chore: make lint happy * fixup! refactor: make KeyboardCodeFromStr() private * refactor: use constexpr lookup table in electron_url_loader_factory * refactor: use constexpr lookup table in electron_api_tray * refactor: use constexpr lookup table in web_contents_preferences.cc * refactor: use constexpr lookup table in content_converter
This commit is contained in:
parent
1eb19f3078
commit
395b608dd5
7 changed files with 349 additions and 460 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "shell/browser/api/electron_api_menu.h"
|
||||
|
@ -29,27 +30,16 @@ struct Converter<electron::TrayIcon::IconType> {
|
|||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::TrayIcon::IconType* out) {
|
||||
using IconType = electron::TrayIcon::IconType;
|
||||
std::string mode;
|
||||
if (ConvertFromV8(isolate, val, &mode)) {
|
||||
if (mode == "none") {
|
||||
*out = IconType::kNone;
|
||||
return true;
|
||||
} else if (mode == "info") {
|
||||
*out = IconType::kInfo;
|
||||
return true;
|
||||
} else if (mode == "warning") {
|
||||
*out = IconType::kWarning;
|
||||
return true;
|
||||
} else if (mode == "error") {
|
||||
*out = IconType::kError;
|
||||
return true;
|
||||
} else if (mode == "custom") {
|
||||
*out = IconType::kCustom;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
using Val = electron::TrayIcon::IconType;
|
||||
static constexpr auto Lookup =
|
||||
base::MakeFixedFlatMapSorted<base::StringPiece, Val>({
|
||||
{"custom", Val::kCustom},
|
||||
{"error", Val::kError},
|
||||
{"info", Val::kInfo},
|
||||
{"none", Val::kNone},
|
||||
{"warning", Val::kWarning},
|
||||
});
|
||||
return FromV8WithLookup(isolate, val, Lookup, out);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue