Skip to content

Commit feeaa4d

Browse files
committed
Simplify arg capacity calculations.
Currently they try to be very precise. But they are wrong, i.e. they don't match what's happening in the loop below. This code isn't hot enough for it to matter that much.
1 parent b75b3b3 commit feeaa4d

File tree

2 files changed

+5
-24
lines changed
  • compiler

2 files changed

+5
-24
lines changed

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,10 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
107107
impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
108108
fn gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> (Type<'gcc>, Vec<Type<'gcc>>, bool, FxHashSet<usize>) {
109109
let mut on_stack_param_indices = FxHashSet::default();
110-
let args_capacity: usize = self.args.iter().map(|arg|
111-
if arg.pad.is_some() {
112-
1
113-
}
114-
else {
115-
0
116-
} +
117-
if let PassMode::Pair(_, _) = arg.mode {
118-
2
119-
} else {
120-
1
121-
}
122-
).sum();
110+
111+
// This capacity calculation is approximate.
123112
let mut argument_tys = Vec::with_capacity(
124-
if let PassMode::Indirect { .. } = self.ret.mode {
125-
1
126-
}
127-
else {
128-
0
129-
} + args_capacity,
113+
self.args.len() + if let PassMode::Indirect { .. } = self.ret.mode { 1 } else { 0 }
130114
);
131115

132116
let return_ty =

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,9 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
328328
let args =
329329
if self.c_variadic { &self.args[..self.fixed_count as usize] } else { &self.args };
330330

331-
let args_capacity: usize = args.iter().map(|arg|
332-
if arg.pad.is_some() { 1 } else { 0 } +
333-
if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
334-
).sum();
331+
// This capacity calculation is approximate.
335332
let mut llargument_tys = Vec::with_capacity(
336-
if let PassMode::Indirect { .. } = self.ret.mode { 1 } else { 0 } + args_capacity,
333+
self.args.len() + if let PassMode::Indirect { .. } = self.ret.mode { 1 } else { 0 },
337334
);
338335

339336
let llreturn_ty = match &self.ret.mode {

0 commit comments

Comments
 (0)