mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-12 05:10:00 +08:00
Undo perf hit to keyword lookups
This commit is contained in:
parent
0fc420f69d
commit
58f740844d
@ -23,6 +23,7 @@
|
|||||||
#include "../dispatchkit/dispatchkit.hpp"
|
#include "../dispatchkit/dispatchkit.hpp"
|
||||||
#include "../dispatchkit/proxy_functions.hpp"
|
#include "../dispatchkit/proxy_functions.hpp"
|
||||||
#include "../dispatchkit/type_info.hpp"
|
#include "../dispatchkit/type_info.hpp"
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace chaiscript {
|
namespace chaiscript {
|
||||||
struct AST_Node;
|
struct AST_Node;
|
||||||
@ -33,13 +34,15 @@ namespace chaiscript
|
|||||||
struct Name_Validator {
|
struct Name_Validator {
|
||||||
static bool is_reserved_word(const std::string &name) noexcept
|
static bool is_reserved_word(const std::string &name) noexcept
|
||||||
{
|
{
|
||||||
static const char *m_reserved_words[]
|
static const std::unordered_set<std::string> words {
|
||||||
= {"def", "fun", "while", "for", "if", "else", "&&", "||", ",", "auto",
|
"def", "fun", "while", "for", "if", "else",
|
||||||
"return", "break", "true", "false", "class", "attr", "var", "global", "GLOBAL", "_",
|
"&&", "||", ",", "auto", "return", "break",
|
||||||
"__LINE__", "__FILE__", "__FUNC__", "__CLASS__"};
|
"true", "false", "class", "attr", "var", "global",
|
||||||
|
"GLOBAL", "_",
|
||||||
|
"__LINE__", "__FILE__", "__FUNC__", "__CLASS__"
|
||||||
|
};
|
||||||
|
|
||||||
return std::any_of(std::begin(m_reserved_words), std::end(m_reserved_words),
|
return words.count(name) == 1;
|
||||||
[&name](const char *str){ return str == name; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool valid_object_name(const std::string &name) noexcept
|
static bool valid_object_name(const std::string &name) noexcept
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user