diff --git a/sqlglotrs/src/token.rs b/sqlglotrs/src/token.rs index 33524691a0..48698fc859 100644 --- a/sqlglotrs/src/token.rs +++ b/sqlglotrs/src/token.rs @@ -49,13 +49,11 @@ impl Token { pub fn append_comments(&self, comments: &mut Vec) { Python::with_gil(|py| { let pylist = self.comments.bind(py); - for comment in comments.iter() { + for comment in comments.drain(..) { if let Err(_) = pylist.append(comment) { panic!("Failed to append comments to the Python list"); } } }); - // Simulate `Vec::append`. - let _ = std::mem::replace(comments, Vec::new()); } } diff --git a/sqlglotrs/src/tokenizer.rs b/sqlglotrs/src/tokenizer.rs index 21b0862ec7..e965fe57c3 100644 --- a/sqlglotrs/src/tokenizer.rs +++ b/sqlglotrs/src/tokenizer.rs @@ -111,7 +111,7 @@ impl<'a> TokenizerState<'a> { fn tokenize(&mut self) -> Result, TokenizerError> { self.scan(None)?; - Ok(std::mem::replace(&mut self.tokens, Vec::new())) + Ok(std::mem::take(&mut self.tokens)) } fn scan(&mut self, until_peek_char: Option) -> Result<(), TokenizerError> { @@ -234,7 +234,7 @@ impl<'a> TokenizerState<'a> { self.column, self.start, self.current - 1, - std::mem::replace(&mut self.comments, Vec::new()), + std::mem::take(&mut self.comments), )); // If we have either a semicolon or a begin token before the command's token, we'll parse