Skip to content

Commit 3e9191f

Browse files
committed
Auto merge of #2225 - JohnTitor:with-capacity, r=jtgeibel
Use `Vec::with_capacity()` as possible It's a minor cleanup, uses `Vec::with_capacity()` as possible to prevent reallocation.
2 parents 3cfa7a1 + 7445214 commit 3e9191f

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/controllers/krate/owners.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn modify_owners(req: &mut dyn Request, add: bool) -> AppResult<Response> {
115115
}
116116

117117
let comma_sep_msg = if add {
118-
let mut msgs = Vec::new();
118+
let mut msgs = Vec::with_capacity(logins.len());
119119
for login in &logins {
120120
let login_test =
121121
|owner: &Owner| owner.login().to_lowercase() == *login.to_lowercase();

src/controllers/krate/publish.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ fn parse_new_headers(req: &mut dyn Request) -> AppResult<EncodableCrateUpload> {
245245
fn empty(s: Option<&String>) -> bool {
246246
s.map_or(true, String::is_empty)
247247
}
248-
let mut missing = Vec::new();
248+
249+
// It can have up to three elements per below conditions.
250+
let mut missing = Vec::with_capacity(3);
249251

250252
if empty(new.description.as_ref()) {
251253
missing.push("description");

src/tasks/dump_db/gen_scripts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ impl VisibilityConfig {
9191
///
9292
/// Returns a vector of table names.
9393
fn topological_sort(&self) -> Vec<&str> {
94-
let mut result = Vec::new();
9594
let mut num_deps = BTreeMap::new();
9695
let mut rev_deps: BTreeMap<_, Vec<_>> = BTreeMap::new();
9796
for (table, config) in self.0.iter() {
@@ -108,6 +107,7 @@ impl VisibilityConfig {
108107
.filter(|(_, &count)| count == 0)
109108
.map(|(&table, _)| table)
110109
.collect();
110+
let mut result = Vec::with_capacity(ready.len());
111111
while let Some(table) = ready.pop_front() {
112112
result.push(table);
113113
for dep in rev_deps.get(table).iter().cloned().flatten() {

0 commit comments

Comments
 (0)