Skip to content

Commit b4acf7a

Browse files
committed
Immediately create an Option instead of reallocating for it later
1 parent eef70a9 commit b4acf7a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
6868

6969
const NO_SCOPE_METADATA: Option<&DIScope> = None;
7070
/// A function that returns an empty list of generic parameter debuginfo nodes.
71-
const NO_GENERICS: for<'ll> fn(&CodegenCx<'ll, '_>) -> SmallVec<&'ll DIType> = |_| SmallVec::new();
71+
const NO_GENERICS: for<'ll> fn(&CodegenCx<'ll, '_>) -> SmallVec<Option<&'ll DIType>> =
72+
|_| SmallVec::new();
7273

7374
// SmallVec is used quite a bit in this module, so create a shorthand.
7475
// The actual number of elements is not so important.
@@ -1287,7 +1288,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
12871288
fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12881289
cx: &CodegenCx<'ll, 'tcx>,
12891290
ty: Ty<'tcx>,
1290-
) -> SmallVec<&'ll DIType> {
1291+
) -> SmallVec<Option<&'ll DIType>> {
12911292
if let ty::Adt(def, args) = *ty.kind() {
12921293
if args.types().next().is_some() {
12931294
let generics = cx.tcx.generics_of(def.did());
@@ -1297,7 +1298,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12971298
kind.as_type().map(|ty| {
12981299
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
12991300
let actual_type_di_node = type_di_node(cx, actual_type);
1300-
cx.create_template_type_parameter(name.as_str(), actual_type_di_node)
1301+
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
13011302
})
13021303
})
13031304
.collect();

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,15 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
257257
cx: &CodegenCx<'ll, 'tcx>,
258258
stub_info: StubInfo<'ll, 'tcx>,
259259
members: impl FnOnce(&CodegenCx<'ll, 'tcx>, &'ll DIType) -> SmallVec<&'ll DIType>,
260-
generics: impl FnOnce(&CodegenCx<'ll, 'tcx>) -> SmallVec<&'ll DIType>,
260+
generics: impl FnOnce(&CodegenCx<'ll, 'tcx>) -> SmallVec<Option<&'ll DIType>>,
261261
) -> DINodeCreationResult<'ll> {
262262
assert_eq!(debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id), None);
263263

264264
debug_context(cx).type_map.insert(stub_info.unique_type_id, stub_info.metadata);
265265

266266
let members: SmallVec<_> =
267267
members(cx, stub_info.metadata).into_iter().map(|node| Some(node)).collect();
268-
let generics: SmallVec<Option<&'ll DIType>> =
269-
generics(cx).into_iter().map(|node| Some(node)).collect();
268+
let generics = generics(cx);
270269

271270
if !(members.is_empty() && generics.is_empty()) {
272271
unsafe {

0 commit comments

Comments
 (0)