Merge pull request #2481 from kolloch/feature/no-clone-in-insert

Input.insert: No need to clone
This commit is contained in:
Pavan Kumar Sunkara 2021-05-13 19:13:00 +01:00 committed by GitHub
commit a4b9bfc97b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,13 +67,11 @@ impl Input {
/// Insert some items to the Input items just after current parsing cursor.
/// Usually used by replaced items recovering.
pub(crate) fn insert(&mut self, insert_items: &[&str]) {
self.items = {
let mut new_items: Vec<OsString> = insert_items.iter().map(OsString::from).collect();
for unparsed_item in &self.items[self.cursor..] {
new_items.push(unparsed_item.clone());
}
new_items
};
self.items = insert_items
.iter()
.map(OsString::from)
.chain(self.items.drain(self.cursor..))
.collect();
self.cursor = 0;
}
}