Skip to content

Commit 7677f41

Browse files
committed
Preallocate some vecs
1 parent 79492cb commit 7677f41

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

crates/hir-ty/src/infer/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl InferenceContext<'_> {
6767
let arg = projection.substitution.as_slice(Interner).get(1)?;
6868
if let Some(subst) = arg.ty(Interner)?.as_tuple() {
6969
let generic_args = subst.as_slice(Interner);
70-
let mut sig_tys = Vec::new();
70+
let mut sig_tys = Vec::with_capacity(generic_args.len() + 1);
7171
for arg in generic_args {
7272
sig_tys.push(arg.ty(Interner)?.clone());
7373
}

crates/hir-ty/src/infer/expr.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a> InferenceContext<'a> {
235235
Expr::Closure { body, args, ret_type, arg_types, closure_kind } => {
236236
assert_eq!(args.len(), arg_types.len());
237237

238-
let mut sig_tys = Vec::new();
238+
let mut sig_tys = Vec::with_capacity(arg_types.len() + 1);
239239

240240
// collect explicitly written argument types
241241
for arg_type in arg_types.iter() {
@@ -256,7 +256,8 @@ impl<'a> InferenceContext<'a> {
256256
num_binders: 0,
257257
sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
258258
substitution: FnSubst(
259-
Substitution::from_iter(Interner, sig_tys.clone()).shifted_in(Interner),
259+
Substitution::from_iter(Interner, sig_tys.iter().cloned())
260+
.shifted_in(Interner),
260261
),
261262
})
262263
.intern(Interner);
@@ -318,16 +319,16 @@ impl<'a> InferenceContext<'a> {
318319
Expr::Call { callee, args, .. } => {
319320
let callee_ty = self.infer_expr(*callee, &Expectation::none());
320321
let mut derefs = Autoderef::new(&mut self.table, callee_ty.clone());
321-
let mut res = None;
322-
let mut derefed_callee = callee_ty.clone();
323-
// manual loop to be able to access `derefs.table`
324-
while let Some((callee_deref_ty, _)) = derefs.next() {
325-
res = derefs.table.callable_sig(&callee_deref_ty, args.len());
326-
if res.is_some() {
327-
derefed_callee = callee_deref_ty;
328-
break;
322+
let (res, derefed_callee) = 'b: {
323+
// manual loop to be able to access `derefs.table`
324+
while let Some((callee_deref_ty, _)) = derefs.next() {
325+
let res = derefs.table.callable_sig(&callee_deref_ty, args.len());
326+
if res.is_some() {
327+
break 'b (res, callee_deref_ty);
328+
}
329329
}
330-
}
330+
(None, callee_ty.clone())
331+
};
331332
// if the function is unresolved, we use is_varargs=true to
332333
// suppress the arg count diagnostic here
333334
let is_varargs =

0 commit comments

Comments
 (0)