From 8744a4e3f2757711f8a78635e6bbcdf6cf86c1e9 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 22 Dec 2024 23:25:48 -0500 Subject: [PATCH] feat(lib): use `const` for `TSCharacterRanges` --- cli/generate/src/render.rs | 6 +----- lib/src/parser.h | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cli/generate/src/render.rs b/cli/generate/src/render.rs index 62993d55..2711ac19 100644 --- a/cli/generate/src/render.rs +++ b/cli/generate/src/render.rs @@ -983,11 +983,7 @@ impl Generator { return; } - add_line!( - self, - "static TSCharacterRange {}[] = {{", - info.constant_name - ); + add_line!(self, "const TSCharacterRange {}[] = {{", info.constant_name); indent!(self); for (ix, range) in characters.ranges().enumerate() { diff --git a/lib/src/parser.h b/lib/src/parser.h index 2338b4a2..13aa49b5 100644 --- a/lib/src/parser.h +++ b/lib/src/parser.h @@ -132,13 +132,13 @@ struct TSLanguage { const char *name; }; -static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { +static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { uint32_t index = 0; uint32_t size = len - index; while (size > 1) { uint32_t half_size = size / 2; uint32_t mid_index = index + half_size; - TSCharacterRange *range = &ranges[mid_index]; + const TSCharacterRange *range = &ranges[mid_index]; if (lookahead >= range->start && lookahead <= range->end) { return true; } else if (lookahead > range->end) { @@ -146,7 +146,7 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t } size -= half_size; } - TSCharacterRange *range = &ranges[index]; + const TSCharacterRange *range = &ranges[index]; return (lookahead >= range->start && lookahead <= range->end); }