mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-01 09:50:46 +08:00
parser_keywords: Use unordered_set instead of arrays
This makes the test mentioned in #5305: for i in (seq 100000); test 1 = 1; end run ~5% faster.
This commit is contained in:
parent
47c1144a3c
commit
9300ec55f0
|
@ -2,6 +2,7 @@
|
||||||
#include "config.h" // IWYU pragma: keep
|
#include "config.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fallback.h" // IWYU pragma: keep
|
#include "fallback.h" // IWYU pragma: keep
|
||||||
|
@ -11,17 +12,17 @@ bool parser_keywords_skip_arguments(const wcstring &cmd) {
|
||||||
return cmd == L"else" || cmd == L"begin";
|
return cmd == L"else" || cmd == L"begin";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *const subcommand_keywords[] = {L"command", L"builtin", L"while", L"exec",
|
static const std::unordered_set<wcstring> subcommand_keywords = {L"command", L"builtin", L"while", L"exec",
|
||||||
L"if", L"and", L"or", L"not"};
|
L"if", L"and", L"or", L"not"};
|
||||||
bool parser_keywords_is_subcommand(const wcstring &cmd) {
|
bool parser_keywords_is_subcommand(const wcstring &cmd) {
|
||||||
return parser_keywords_skip_arguments(cmd) || contains(subcommand_keywords, cmd);
|
return parser_keywords_skip_arguments(cmd) || contains(subcommand_keywords, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const wchar_t *const block_keywords[] = {L"for", L"while", L"if",
|
static const std::unordered_set<wcstring> block_keywords = {L"for", L"while", L"if",
|
||||||
L"function", L"switch", L"begin"};
|
L"function", L"switch", L"begin"};
|
||||||
bool parser_keywords_is_block(const wcstring &word) { return contains(block_keywords, word); }
|
bool parser_keywords_is_block(const wcstring &word) { return contains(block_keywords, word); }
|
||||||
|
|
||||||
static const wchar_t *const reserved_keywords[] = {L"end", L"case", L"else", L"return",
|
static const std::unordered_set<wcstring> reserved_keywords = {L"end", L"case", L"else", L"return",
|
||||||
L"continue", L"break", L"argparse", L"read",
|
L"continue", L"break", L"argparse", L"read",
|
||||||
L"set", L"status", L"test", L"["};
|
L"set", L"status", L"test", L"["};
|
||||||
bool parser_keywords_is_reserved(const wcstring &word) {
|
bool parser_keywords_is_reserved(const wcstring &word) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user