This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 153e7c57 perf: optimize `make_word()` to avoid unnecessary allocations
(#2176)
153e7c57 is described below
commit 153e7c57465476aa7350672c5cee4f1ef02b7365
Author: Andy Grove <[email protected]>
AuthorDate: Sat Jan 24 04:30:51 2026 -0700
perf: optimize `make_word()` to avoid unnecessary allocations (#2176)
Co-authored-by: Claude Opus 4.5 <[email protected]>
---
src/tokenizer.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 42fa5b61..8c33ad3d 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -413,16 +413,22 @@ impl Token {
/// When `quote_style` is `None`, the parser attempts a case-insensitive
keyword
/// lookup and sets the `Word::keyword` accordingly.
pub fn make_word(word: &str, quote_style: Option<char>) -> Self {
- let word_uppercase = word.to_uppercase();
+ // Only perform keyword lookup for unquoted identifiers.
+ // Use to_ascii_uppercase() since SQL keywords are ASCII,
+ // avoiding Unicode case conversion overhead.
+ let keyword = if quote_style.is_none() {
+ let word_uppercase = word.to_ascii_uppercase();
+ ALL_KEYWORDS
+ .binary_search(&word_uppercase.as_str())
+ .map_or(Keyword::NoKeyword, |x| ALL_KEYWORDS_INDEX[x])
+ } else {
+ Keyword::NoKeyword
+ };
+
Token::Word(Word {
value: word.to_string(),
quote_style,
- keyword: if quote_style.is_none() {
- let keyword =
ALL_KEYWORDS.binary_search(&word_uppercase.as_str());
- keyword.map_or(Keyword::NoKeyword, |x| ALL_KEYWORDS_INDEX[x])
- } else {
- Keyword::NoKeyword
- },
+ keyword,
})
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]