Skip to content

Commit c2a0559

Browse files
committed
refactor: removed allocation in check fn
parse::check_on_update_expr_is_valid - using local const instead of vec for valid object names
1 parent 653cd2b commit c2a0559

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/parser.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,21 +6320,24 @@ impl<'a> Parser<'a> {
63206320
}
63216321

63226322
fn check_on_update_expr_is_valid(expr: &Expr) -> Result<(), ParserError> {
6323-
let valid_object_names: [ObjectName; 4] = [
6324-
ObjectName(vec!["CURRENT_TIMESTAMP".into()]),
6325-
ObjectName(vec!["LOCALTIME".into()]),
6326-
ObjectName(vec!["LOCALTIMESTAMP".into()]),
6327-
ObjectName(vec!["NOW".into()]),
6323+
const VALID_FN_NAMES: [&str; 4] = [
6324+
keywords::CURRENT_TIMESTAMP,
6325+
keywords::LOCALTIME,
6326+
keywords::LOCALTIMESTAMP,
6327+
"NOW",
63286328
];
63296329

63306330
if let Expr::Function(f) = expr {
6331-
if valid_object_names.contains(&f.name) {
6332-
return Ok(());
6331+
if let Some(fn_name_ident) = f.name.0.first() {
6332+
if VALID_FN_NAMES.contains(fn_name_ident.value.as_str()) {
6333+
return Ok(());
6334+
}
63336335
}
63346336
}
6337+
63356338
Err(ParserError::ParserError(format!(
63366339
"Expected one of '{}' after ON UPDATE in column definition",
6337-
valid_object_names.map(|x| x.to_string()).join("', '")
6340+
VALID_FN_NAMES.map(|x| x.to_string()).join("', '")
63386341
)))
63396342
}
63406343
}

0 commit comments

Comments
 (0)