perf(lexer): reduce checks on ident -> keyword (#783)

This commit is contained in:
Boshen 2023-08-24 18:43:03 +08:00 committed by GitHub
parent c8a215ea5e
commit a272c1ffe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 105 deletions

View file

@ -7,6 +7,7 @@ extend-exclude = [
"tasks/coverage/test262", "tasks/coverage/test262",
"tasks/coverage/babel", "tasks/coverage/babel",
"tasks/coverage/typescript", "tasks/coverage/typescript",
"crates/oxc_parser/src/lexer/mod.rs",
"**/*.snap", "**/*.snap",
"pnpm-lock.yaml", "pnpm-lock.yaml",
] ]

View file

@ -1645,170 +1645,170 @@ const TLD: ByteHandler = |lexer| {
Kind::Tilde Kind::Tilde
}; };
const L_A: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_A: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"abstract" => Kind::Abstract, "wait" => Kind::Await,
"accessor" => Kind::Accessor, "sync" => Kind::Async,
"any" => Kind::Any, "bstract" => Kind::Abstract,
"as" => Kind::As, "ccessor" => Kind::Accessor,
"assert" => Kind::Assert, "ny" => Kind::Any,
"asserts" => Kind::Asserts, "s" => Kind::As,
"async" => Kind::Async, "ssert" => Kind::Assert,
"await" => Kind::Await, "sserts" => Kind::Asserts,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_B: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_B: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"bigint" => Kind::BigInt, "reak" => Kind::Break,
"boolean" => Kind::Boolean, "oolean" => Kind::Boolean,
"break" => Kind::Break, "igint" => Kind::BigInt,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_C: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_C: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"case" => Kind::Case, "onst" => Kind::Const,
"catch" => Kind::Catch, "lass" => Kind::Class,
"class" => Kind::Class, "ontinue" => Kind::Continue,
"const" => Kind::Const, "atch" => Kind::Catch,
"constructor" => Kind::Constructor, "ase" => Kind::Case,
"continue" => Kind::Continue, "onstructor" => Kind::Constructor,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_D: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_D: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"debugger" => Kind::Debugger, "o" => Kind::Do,
"declare" => Kind::Declare, "elete" => Kind::Delete,
"default" => Kind::Default, "eclare" => Kind::Declare,
"delete" => Kind::Delete, "efault" => Kind::Default,
"do" => Kind::Do, "ebugger" => Kind::Debugger,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_E: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_E: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"else" => Kind::Else, "lse" => Kind::Else,
"enum" => Kind::Enum, "num" => Kind::Enum,
"export" => Kind::Export, "xport" => Kind::Export,
"extends" => Kind::Extends, "xtends" => Kind::Extends,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_F: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_F: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"false" => Kind::False, "unction" => Kind::Function,
"finally" => Kind::Finally, "alse" => Kind::False,
"for" => Kind::For, "or" => Kind::For,
"from" => Kind::From, "inally" => Kind::Finally,
"function" => Kind::Function, "rom" => Kind::From,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_G: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_G: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"get" => Kind::Get, "et" => Kind::Get,
"global" => Kind::Global, "lobal" => Kind::Global,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_I: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_I: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"if" => Kind::If, "f" => Kind::If,
"implements" => Kind::Implements, "nstanceof" => Kind::Instanceof,
"import" => Kind::Import, "n" => Kind::In,
"in" => Kind::In, "mplements" => Kind::Implements,
"infer" => Kind::Infer, "mport" => Kind::Import,
"instanceof" => Kind::Instanceof, "nfer" => Kind::Infer,
"interface" => Kind::Interface, "nterface" => Kind::Interface,
"intrinsic" => Kind::Intrinsic, "ntrinsic" => Kind::Intrinsic,
"is" => Kind::Is, "s" => Kind::Is,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_K: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_K: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"keyof" => Kind::KeyOf, "eyof" => Kind::KeyOf,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_L: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_L: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"let" => Kind::Let, "et" => Kind::Let,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_M: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_M: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"meta" => Kind::Meta, "eta" => Kind::Meta,
"module" => Kind::Module, "odule" => Kind::Module,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_N: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_N: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"namespace" => Kind::Namespace, "ull" => Kind::Null,
"never" => Kind::Never, "ew" => Kind::New,
"new" => Kind::New, "umber" => Kind::Number,
"null" => Kind::Null, "amespace" => Kind::Namespace,
"number" => Kind::Number, "ever" => Kind::Never,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_O: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_O: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"object" => Kind::Object, "f" => Kind::Of,
"of" => Kind::Of, "bject" => Kind::Object,
"out" => Kind::Out, "ut" => Kind::Out,
"override" => Kind::Override, "verride" => Kind::Override,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_P: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_P: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"package" => Kind::Package, "ackage" => Kind::Package,
"private" => Kind::Private, "rivate" => Kind::Private,
"protected" => Kind::Protected, "rotected" => Kind::Protected,
"public" => Kind::Public, "ublic" => Kind::Public,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_R: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_R: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"readonly" => Kind::Readonly, "eturn" => Kind::Return,
"require" => Kind::Require, "equire" => Kind::Require,
"return" => Kind::Return, "eadonly" => Kind::Readonly,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_S: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_S: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"satisfies" => Kind::Satisfies, "et" => Kind::Set,
"set" => Kind::Set, "uper" => Kind::Super,
"static" => Kind::Static, "witch" => Kind::Switch,
"string" => Kind::String, "tatic" => Kind::Static,
"super" => Kind::Super, "ymbol" => Kind::Symbol,
"switch" => Kind::Switch, "tring" => Kind::String,
"symbol" => Kind::Symbol, "atisfies" => Kind::Satisfies,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_T: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_T: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"target" => Kind::Target, "his" => Kind::This,
"this" => Kind::This, "rue" => Kind::True,
"throw" => Kind::Throw, "hrow" => Kind::Throw,
"true" => Kind::True, "ry" => Kind::Try,
"try" => Kind::Try, "ypeof" => Kind::Typeof,
"type" => Kind::Type, "arget" => Kind::Target,
"typeof" => Kind::Typeof, "ype" => Kind::Type,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_U: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_U: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"undefined" => Kind::Undefined, "ndefined" => Kind::Undefined,
"unique" => Kind::Unique, "nique" => Kind::Unique,
"unknown" => Kind::Unknown, "nknown" => Kind::Unknown,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_V: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_V: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"var" => Kind::Var, "ar" => Kind::Var,
"void" => Kind::Void, "oid" => Kind::Void,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_W: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_W: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"while" => Kind::While, "hile" => Kind::While,
"with" => Kind::With, "ith" => Kind::With,
_ => Kind::Ident, _ => Kind::Ident,
}; };
const L_Y: ByteHandler = |lexer| match lexer.identifier_name_handler() { const L_Y: ByteHandler = |lexer| match &lexer.identifier_name_handler()[1..] {
"yield" => Kind::Yield, "ield" => Kind::Yield,
_ => Kind::Ident, _ => Kind::Ident,
}; };