Skip to content

Commit

Permalink
Avoid cloning during token creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Dec 14, 2024
1 parent 885aa93 commit 93c70d2
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 146 deletions.
3 changes: 2 additions & 1 deletion src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ macro_rules! define_keywords {
};
}

// The following keywords should be sorted to be able to match using binary search
// Notes: The following keywords should be sorted to be able to match using
// binary search
define_keywords!(
ABORT,
ABS,
Expand Down
38 changes: 25 additions & 13 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4160,7 +4160,7 @@ impl<'a> Parser<'a> {
Keyword::ARCHIVE => Ok(Some(CreateFunctionUsing::Archive(uri))),
_ => self.expected(
"JAR, FILE or ARCHIVE, got {:?}",
TokenWithSpan::wrap(Token::make_keyword(format!("{keyword:?}").as_str())),
TokenWithSpan::wrap(Token::make_keyword(format!("{keyword:?}"))),
),
}
}
Expand Down Expand Up @@ -6495,28 +6495,28 @@ impl<'a> Parser<'a> {
{
// Support AUTO_INCREMENT for MySQL
Ok(Some(ColumnOption::DialectSpecific(vec![
Token::make_keyword("AUTO_INCREMENT"),
Token::make_keyword("AUTO_INCREMENT".into()),
])))
} else if self.parse_keyword(Keyword::AUTOINCREMENT)
&& dialect_of!(self is SQLiteDialect | GenericDialect)
{
// Support AUTOINCREMENT for SQLite
Ok(Some(ColumnOption::DialectSpecific(vec![
Token::make_keyword("AUTOINCREMENT"),
Token::make_keyword("AUTOINCREMENT".into()),
])))
} else if self.parse_keyword(Keyword::ASC)
&& self.dialect.supports_asc_desc_in_column_definition()
{
// Support ASC for SQLite
Ok(Some(ColumnOption::DialectSpecific(vec![
Token::make_keyword("ASC"),
Token::make_keyword("ASC".into()),
])))
} else if self.parse_keyword(Keyword::DESC)
&& self.dialect.supports_asc_desc_in_column_definition()
{
// Support DESC for SQLite
Ok(Some(ColumnOption::DialectSpecific(vec![
Token::make_keyword("DESC"),
Token::make_keyword("DESC".into()),
])))
} else if self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
&& dialect_of!(self is MySqlDialect | GenericDialect)
Expand Down Expand Up @@ -6889,7 +6889,7 @@ impl<'a> Parser<'a> {
return self.expected(
"FULLTEXT or SPATIAL option without constraint name",
TokenWithSpan {
token: Token::make_keyword(&name.to_string()),
token: Token::make_keyword(name.to_string()),
span: next_token.span,
},
);
Expand Down Expand Up @@ -13028,17 +13028,29 @@ mod tests {
fn test_prev_index() {
let sql = "SELECT version";
all_dialects().run_parser_method(sql, |parser| {
assert_eq!(parser.peek_token(), Token::make_keyword("SELECT"));
assert_eq!(parser.next_token(), Token::make_keyword("SELECT"));
assert_eq!(parser.peek_token(), Token::make_keyword("SELECT".into()));
assert_eq!(parser.next_token(), Token::make_keyword("SELECT".into()));
parser.prev_token();
assert_eq!(parser.next_token(), Token::make_keyword("SELECT"));
assert_eq!(parser.next_token(), Token::make_word("version", None));
assert_eq!(parser.next_token(), Token::make_keyword("SELECT".into()));
assert_eq!(
parser.next_token(),
Token::make_word("version".into(), None)
);
parser.prev_token();
assert_eq!(parser.peek_token(), Token::make_word("version", None));
assert_eq!(parser.next_token(), Token::make_word("version", None));
assert_eq!(
parser.peek_token(),
Token::make_word("version".into(), None)
);
assert_eq!(
parser.next_token(),
Token::make_word("version".into(), None)
);
assert_eq!(parser.peek_token(), Token::EOF);
parser.prev_token();
assert_eq!(parser.next_token(), Token::make_word("version", None));
assert_eq!(
parser.next_token(),
Token::make_word("version".into(), None)
);
assert_eq!(parser.next_token(), Token::EOF);
assert_eq!(parser.next_token(), Token::EOF);
parser.prev_token();
Expand Down
Loading

0 comments on commit 93c70d2

Please sign in to comment.