Skip to content

Commit 3d7169f

Browse files
committed
Avoid cloning tokens in parse_data_type_helper
1 parent 366b913 commit 3d7169f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/parser/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8093,9 +8093,10 @@ impl<'a> Parser<'a> {
80938093
fn parse_data_type_helper(
80948094
&mut self,
80958095
) -> Result<(DataType, MatchedTrailingBracket), ParserError> {
8096-
let next_token = self.next_token();
8096+
let dialect = self.dialect;
8097+
let next_token = self.next_token_ref();
80978098
let mut trailing_bracket: MatchedTrailingBracket = false.into();
8098-
let mut data = match next_token.token {
8099+
let mut data = match &next_token.token {
80998100
Token::Word(w) => match w.keyword {
81008101
Keyword::BOOLEAN => Ok(DataType::Boolean),
81018102
Keyword::BOOL => Ok(DataType::Bool),
@@ -8335,12 +8336,12 @@ impl<'a> Parser<'a> {
83358336
))))
83368337
}
83378338
}
8338-
Keyword::STRUCT if dialect_of!(self is DuckDbDialect) => {
8339+
Keyword::STRUCT if dialect_is!(dialect is DuckDbDialect) => {
83398340
self.prev_token();
83408341
let field_defs = self.parse_duckdb_struct_type_def()?;
83418342
Ok(DataType::Struct(field_defs, StructBracketKind::Parentheses))
83428343
}
8343-
Keyword::STRUCT if dialect_of!(self is BigQueryDialect | GenericDialect) => {
8344+
Keyword::STRUCT if dialect_is!(dialect is BigQueryDialect | GenericDialect) => {
83448345
self.prev_token();
83458346
let (field_defs, _trailing_bracket) =
83468347
self.parse_struct_type_def(Self::parse_struct_field_def)?;
@@ -8350,32 +8351,32 @@ impl<'a> Parser<'a> {
83508351
StructBracketKind::AngleBrackets,
83518352
))
83528353
}
8353-
Keyword::UNION if dialect_of!(self is DuckDbDialect | GenericDialect) => {
8354+
Keyword::UNION if dialect_is!(dialect is DuckDbDialect | GenericDialect) => {
83548355
self.prev_token();
83558356
let fields = self.parse_union_type_def()?;
83568357
Ok(DataType::Union(fields))
83578358
}
8358-
Keyword::NULLABLE if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
8359+
Keyword::NULLABLE if dialect_is!(dialect is ClickHouseDialect | GenericDialect) => {
83598360
Ok(self.parse_sub_type(DataType::Nullable)?)
83608361
}
8361-
Keyword::LOWCARDINALITY if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
8362+
Keyword::LOWCARDINALITY if dialect_is!(dialect is ClickHouseDialect | GenericDialect) => {
83628363
Ok(self.parse_sub_type(DataType::LowCardinality)?)
83638364
}
8364-
Keyword::MAP if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
8365+
Keyword::MAP if dialect_is!(dialect is ClickHouseDialect | GenericDialect) => {
83658366
self.prev_token();
83668367
let (key_data_type, value_data_type) = self.parse_click_house_map_def()?;
83678368
Ok(DataType::Map(
83688369
Box::new(key_data_type),
83698370
Box::new(value_data_type),
83708371
))
83718372
}
8372-
Keyword::NESTED if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
8373+
Keyword::NESTED if dialect_is!(dialect is ClickHouseDialect | GenericDialect) => {
83738374
self.expect_token(&Token::LParen)?;
83748375
let field_defs = self.parse_comma_separated(Parser::parse_column_def)?;
83758376
self.expect_token(&Token::RParen)?;
83768377
Ok(DataType::Nested(field_defs))
83778378
}
8378-
Keyword::TUPLE if dialect_of!(self is ClickHouseDialect | GenericDialect) => {
8379+
Keyword::TUPLE if dialect_is!(dialect is ClickHouseDialect | GenericDialect) => {
83798380
self.prev_token();
83808381
let field_defs = self.parse_click_house_tuple_def()?;
83818382
Ok(DataType::Tuple(field_defs))
@@ -8391,7 +8392,7 @@ impl<'a> Parser<'a> {
83918392
}
83928393
}
83938394
},
8394-
_ => self.expected("a data type name", next_token),
8395+
_ => self.expected_current("a data type name"),
83958396
}?;
83968397

83978398
// Parse array data types. Note: this is postgresql-specific and different from

0 commit comments

Comments
 (0)