mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 14:51:03 +01:00
Support lexing characters (#5893)
Adapts `StringLiteral` to lex characters. Adds a `CharLiteral` token, which contains a `CharLiteralValue` which is a straight unicode code point (suggested by zygoloid). --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
c707a6deaa
commit
cae8aa3adf
@@ -92,54 +92,56 @@ static void BM_SimpleStringValue(benchmark::State& state, int size,
|
||||
std::string x(introducer);
|
||||
x.append(size, 'a');
|
||||
if (add_escape) {
|
||||
// Adds a basic escape that forces ComputeValue to generate a new string.
|
||||
// Adds a basic escape that forces ComputeStringValue to generate a new
|
||||
// string.
|
||||
x.append("\\\\");
|
||||
}
|
||||
x.append(terminator);
|
||||
for (auto _ : state) {
|
||||
StringLiteral::Lex(x)->ComputeValue(
|
||||
StringLiteral::Lex(x)->ComputeStringValue(
|
||||
allocator, Diagnostics::NullEmitter<const char*>());
|
||||
}
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_NoGenerate_Short(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_NoGenerate_Short(benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10, "\"", /*add_escape=*/false, "\"");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_NoGenerate_Long(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_NoGenerate_Long(benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10000, "\"", /*add_escape=*/false, "\"");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_WillGenerate_Short(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_WillGenerate_Short(benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10, "\"", /*add_escape=*/true, "\"");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_WillGenerate_Long(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_WillGenerate_Long(benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10000, "\"", /*add_escape=*/true, "\"");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_WillGenerate_Multiline(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_WillGenerate_Multiline(
|
||||
benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10000, "'''\n", /*add_escape=*/true, "\n'''");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_WillGenerate_MultilineDoubleQuote(
|
||||
static void BM_ComputeStringValue_WillGenerate_MultilineDoubleQuote(
|
||||
benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10000, "\"\"\"\n", /*add_escape=*/true,
|
||||
"\n\"\"\"");
|
||||
}
|
||||
|
||||
static void BM_ComputeValue_WillGenerate_Raw(benchmark::State& state) {
|
||||
static void BM_ComputeStringValue_WillGenerate_Raw(benchmark::State& state) {
|
||||
BM_SimpleStringValue(state, 10000, "#\"", /*add_escape=*/true, "\"#");
|
||||
}
|
||||
|
||||
BENCHMARK(BM_ComputeValue_NoGenerate_Short);
|
||||
BENCHMARK(BM_ComputeValue_NoGenerate_Long);
|
||||
BENCHMARK(BM_ComputeStringValue_NoGenerate_Short);
|
||||
BENCHMARK(BM_ComputeStringValue_NoGenerate_Long);
|
||||
|
||||
BENCHMARK(BM_ComputeValue_WillGenerate_Short);
|
||||
BENCHMARK(BM_ComputeValue_WillGenerate_Long);
|
||||
BENCHMARK(BM_ComputeValue_WillGenerate_Multiline);
|
||||
BENCHMARK(BM_ComputeValue_WillGenerate_MultilineDoubleQuote);
|
||||
BENCHMARK(BM_ComputeValue_WillGenerate_Raw);
|
||||
BENCHMARK(BM_ComputeStringValue_WillGenerate_Short);
|
||||
BENCHMARK(BM_ComputeStringValue_WillGenerate_Long);
|
||||
BENCHMARK(BM_ComputeStringValue_WillGenerate_Multiline);
|
||||
BENCHMARK(BM_ComputeStringValue_WillGenerate_MultilineDoubleQuote);
|
||||
BENCHMARK(BM_ComputeStringValue_WillGenerate_Raw);
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Lex
|
||||
|
||||
Reference in New Issue
Block a user