use Vec::with_capaciity for bytes methods

This commit is contained in:
Jeong YunWon
2020-01-11 00:04:36 +09:00
parent eb4904b4ae
commit 0b9bee9973

View File

@@ -685,7 +685,7 @@ impl PyByteInner {
}
pub fn capitalize(&self) -> Vec<u8> {
let mut new: Vec<u8> = Vec::new();
let mut new: Vec<u8> = Vec::with_capacity(self.elements.len());
if let Some((first, second)) = self.elements.split_first() {
new.push(first.to_ascii_uppercase());
second.iter().for_each(|x| new.push(x.to_ascii_lowercase()));
@@ -932,7 +932,11 @@ impl PyByteInner {
) -> PyResult<Vec<u8>> {
let (table, delete) = options.get_value(vm)?;
let mut res = Vec::new();
let mut res = if delete.is_empty() {
Vec::with_capacity(self.elements.len())
} else {
Vec::new()
};
for i in self.elements.iter() {
if !delete.contains(&i) {