Skip to content

Commit 81436eb

Browse files
committed
Use SmallVec for the bundles vectors.
They never have a length of more than two. So this commit changes them to `SmallVec<[_; 2]>`. Also, we possibly push `None` values and then filter those `None` values out again with `retain`. So this commit removes the `retain` and instead only pushes the values if they are `Some(_)`.
1 parent d20b1a8 commit 81436eb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc_span::Span;
2323
use rustc_symbol_mangling::typeid::{kcfi_typeid_for_fnabi, typeid_for_fnabi, TypeIdOptions};
2424
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
2525
use rustc_target::spec::{HasTargetSpec, SanitizerSet, Target};
26+
use smallvec::SmallVec;
2627
use std::borrow::Cow;
2728
use std::iter;
2829
use std::ops::Deref;
@@ -225,17 +226,21 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
225226
let args = self.check_call("invoke", llty, llfn, args);
226227
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
227228
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
228-
let mut bundles = vec![funclet_bundle];
229+
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
230+
if funclet_bundle.is_some() {
231+
bundles.push(funclet_bundle);
232+
}
229233

230234
// Emit CFI pointer type membership test
231235
self.cfi_type_test(fn_attrs, fn_abi, llfn);
232236

233237
// Emit KCFI operand bundle
234238
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, llfn);
235239
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
236-
bundles.push(kcfi_bundle);
240+
if kcfi_bundle.is_some() {
241+
bundles.push(kcfi_bundle);
242+
}
237243

238-
bundles.retain(|bundle| bundle.is_some());
239244
let invoke = unsafe {
240245
llvm::LLVMRustBuildInvoke(
241246
self.llbuilder,
@@ -1189,17 +1194,21 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11891194
let args = self.check_call("call", llty, llfn, args);
11901195
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
11911196
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
1192-
let mut bundles = vec![funclet_bundle];
1197+
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
1198+
if funclet_bundle.is_some() {
1199+
bundles.push(funclet_bundle);
1200+
}
11931201

11941202
// Emit CFI pointer type membership test
11951203
self.cfi_type_test(fn_attrs, fn_abi, llfn);
11961204

11971205
// Emit KCFI operand bundle
11981206
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, llfn);
11991207
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
1200-
bundles.push(kcfi_bundle);
1208+
if kcfi_bundle.is_some() {
1209+
bundles.push(kcfi_bundle);
1210+
}
12011211

1202-
bundles.retain(|bundle| bundle.is_some());
12031212
let call = unsafe {
12041213
llvm::LLVMRustBuildCall(
12051214
self.llbuilder,

0 commit comments

Comments
 (0)