mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 13:48:31 +00:00
Instead of using a table to select a bool parameter, this embeds the first character as a template parameter and uses `if constexpr` in the dispatch body to only test multi-character symbols with that start with that character. Also template the one-char symbol lexing dispatch routines to remove runtime lookup in the bool table, and use constexpr property queries of the token kinds. Last but not least, add a table to precompute a table at compile time to synthesize `LexError` based on the last byte. Benchmark results (./scripts/bench_runner.py --runs=12, -march=x86-64-v3): - BM_CompileApiFileDenseDecls<Lang::Carbon, Phase::Lex>/65536: CPU Time: -5.297% - BM_CompileApiFileDenseDecls<Lang::Carbon, Phase::Lex>/262144: CPU Time: -4.936% - BM_RandomSource: CPU Time: -4.475%, tokens_per_second: +4.684% - BM_GroupingSymbols/32/32/32: CPU Time: -3.215%, tokens_per_second: +3.321% Assisted-by: Antigravity with Gemini
15 lines
446 B
C++
15 lines
446 B
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/lex/token_kind.h"
|
|
|
|
namespace Carbon::Lex {
|
|
|
|
CARBON_DEFINE_ENUM_CLASS_NAMES(TokenKind) {
|
|
#define CARBON_TOKEN(TokenName) CARBON_ENUM_CLASS_NAME_STRING(TokenName)
|
|
#include "toolchain/lex/token_kind.def"
|
|
};
|
|
|
|
} // namespace Carbon::Lex
|