Skip to content

Commit

Permalink
Optimize ASCII case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Apr 15, 2024
1 parent b49ac3b commit 3ac191b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion scripts/make_unicode_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ def main(input_file, output_file):
print(" };", file=output_file)
print(file=output_file)

print(" if (codepoint > 0x110000) codepoint = 0x110000;", file=output_file)
print(" if (JSON5EncoderCpp_expect(codepoint < 256, true)) {", file=output_file)
print(" return (demiplane_data[0][codepoint / 4] >> (2 * (codepoint % 4))) % 4;", file=output_file)
print(" }", file=output_file)
print(file=output_file)
print(" if (codepoint > 0x110000) codepoint = 0x110000;", file=output_file)
print(" std::uint32_t fst_row = codepoint / 0x100;", file=output_file)
print(" std::uint32_t fst_col = codepoint % 0x100;", file=output_file)
print(" std::uint32_t snd_row = fst_row / 64;", file=output_file)
Expand Down
5 changes: 4 additions & 1 deletion src/_unicode_cat_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,11 @@ static unsigned unicode_cat_of(std::uint32_t codepoint) {
0x0cu, 0x0cu, 0x0cu, 0x0cu, 0x0eu, 0x0cu, 0x0cu, 0x0cu,
};

if (codepoint > 0x110000) codepoint = 0x110000;
if (JSON5EncoderCpp_expect(codepoint < 256, true)) {
return (demiplane_data[0][codepoint / 4] >> (2 * (codepoint % 4))) % 4;
}

if (codepoint > 0x110000) codepoint = 0x110000;
std::uint32_t fst_row = codepoint / 0x100;
std::uint32_t fst_col = codepoint % 0x100;
std::uint32_t snd_row = fst_row / 64;
Expand Down

0 comments on commit 3ac191b

Please sign in to comment.