-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve parsing speed by avoiding some clones in parse_identifier #1624
Conversation
@@ -970,15 +970,15 @@ impl<'a> Parser<'a> { | |||
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => { | |||
if self.peek_token().token == Token::Period { | |||
let mut id_parts: Vec<Ident> = vec![match t { | |||
Token::Word(w) => w.to_ident(next_token.span), | |||
Token::Word(w) => w.into_ident(next_token.span), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w.to_ident
cloned (copied) the string. info_ident
simply reuses the string
@@ -1108,7 +1108,7 @@ impl<'a> Parser<'a> { | |||
if dialect_of!(self is PostgreSqlDialect | GenericDialect) => | |||
{ | |||
Ok(Some(Expr::Function(Function { | |||
name: ObjectName(vec![w.to_ident(w_span)]), | |||
name: ObjectName(vec![w.clone().into_ident(w_span)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case I couldn't figure out (yet) how to avoid this clone given that &w
is passed in
This PR doesn't increase the number of clones done, but it makes it more explicit when they are happening
@@ -13475,13 +13477,23 @@ impl<'a> Parser<'a> { | |||
} | |||
|
|||
impl Word { | |||
#[deprecated(since = "0.55.0", note = "please use `into_ident` instead")] | |||
pub fn to_ident(&self, span: Span) -> Ident { | |||
Ident { | |||
value: self.value.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to_indent
clones self.value
@@ -13475,13 +13477,23 @@ impl<'a> Parser<'a> { | |||
} | |||
|
|||
impl Word { | |||
#[deprecated(since = "0.54.0", note = "please use `into_ident` instead")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to help any downstream crates that may also use this function with a deprecation notice rather than simply removing the function immediately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -13475,13 +13477,23 @@ impl<'a> Parser<'a> { | |||
} | |||
|
|||
impl Word { | |||
#[deprecated(since = "0.54.0", note = "please use `into_ident` instead")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
Token
s as much #1558I made a flamegraph of the
sqlparser_bench
and found a few unnecessary clonesThis PR avoids a clone (string copy) in parse_identifier.
I don't think this will make things much faster (yet), but it makes clear where the cloning is happening.
I hope to optimize the speed of parsing identifiers more as a follow on PR.