aya-obj: s/types.types[i]/*t/ where possible

We already have a mutable reference in scope, use it where possible.
pull/734/head
Tamir Duberstein 1 year ago
parent 84d5791d4e
commit dfb6020a1d
No known key found for this signature in database

@ -517,7 +517,7 @@ impl Btf {
} }
// Sanitize VAR if they are not supported. // Sanitize VAR if they are not supported.
BtfType::Var(v) if !features.btf_datasec => { BtfType::Var(v) if !features.btf_datasec => {
types.types[i] = BtfType::Int(Int::new(v.name_offset, 1, IntEncoding::None, 0)); *t = BtfType::Int(Int::new(v.name_offset, 1, IntEncoding::None, 0));
} }
// Sanitize DATASEC if they are not supported. // Sanitize DATASEC if they are not supported.
BtfType::DataSec(d) if !features.btf_datasec => { BtfType::DataSec(d) if !features.btf_datasec => {
@ -548,8 +548,9 @@ impl Btf {
}) })
.collect(); .collect();
types.types[i] = // Must reborrow here because we borrow `types` immutably above.
BtfType::Struct(Struct::new(name_offset, members, entries.len() as u32)); let t = &mut types.types[i];
*t = BtfType::Struct(Struct::new(name_offset, members, entries.len() as u32));
} }
// Fixup DATASEC. // Fixup DATASEC.
// //
@ -620,7 +621,10 @@ impl Btf {
} }
} }
fixed_section.entries = entries; fixed_section.entries = entries;
types.types[i] = BtfType::DataSec(fixed_section);
// Must reborrow here because we borrow `types` immutably above.
let t = &mut types.types[i];
*t = BtfType::DataSec(fixed_section);
} }
} }
// Fixup FUNC_PROTO. // Fixup FUNC_PROTO.
@ -643,7 +647,7 @@ impl Btf {
}) })
.collect(); .collect();
let enum_type = BtfType::Enum(Enum::new(ty.name_offset, false, members)); let enum_type = BtfType::Enum(Enum::new(ty.name_offset, false, members));
types.types[i] = enum_type; *t = enum_type;
} }
// Sanitize FUNC. // Sanitize FUNC.
BtfType::Func(ty) => { BtfType::Func(ty) => {
@ -651,9 +655,7 @@ impl Btf {
// Sanitize FUNC. // Sanitize FUNC.
if !features.btf_func { if !features.btf_func {
debug!("{}: not supported. replacing with TYPEDEF", kind); debug!("{}: not supported. replacing with TYPEDEF", kind);
let typedef_type = *t = BtfType::Typedef(Typedef::new(ty.name_offset, ty.btf_type));
BtfType::Typedef(Typedef::new(ty.name_offset, ty.btf_type));
types.types[i] = typedef_type;
} else if !features.btf_func_global } else if !features.btf_func_global
|| name == "memset" || name == "memset"
|| name == "memcpy" || name == "memcpy"
@ -681,20 +683,17 @@ impl Btf {
// Sanitize FLOAT. // Sanitize FLOAT.
BtfType::Float(ty) if !features.btf_float => { BtfType::Float(ty) if !features.btf_float => {
debug!("{}: not supported. replacing with STRUCT", kind); debug!("{}: not supported. replacing with STRUCT", kind);
let struct_ty = BtfType::Struct(Struct::new(0, vec![], ty.size)); *t = BtfType::Struct(Struct::new(0, vec![], ty.size));
types.types[i] = struct_ty;
} }
// Sanitize DECL_TAG. // Sanitize DECL_TAG.
BtfType::DeclTag(ty) if !features.btf_decl_tag => { BtfType::DeclTag(ty) if !features.btf_decl_tag => {
debug!("{}: not supported. replacing with INT", kind); debug!("{}: not supported. replacing with INT", kind);
let int_type = BtfType::Int(Int::new(ty.name_offset, 1, IntEncoding::None, 0)); *t = BtfType::Int(Int::new(ty.name_offset, 1, IntEncoding::None, 0));
types.types[i] = int_type;
} }
// Sanitize TYPE_TAG. // Sanitize TYPE_TAG.
BtfType::TypeTag(ty) if !features.btf_type_tag => { BtfType::TypeTag(ty) if !features.btf_type_tag => {
debug!("{}: not supported. replacing with CONST", kind); debug!("{}: not supported. replacing with CONST", kind);
let const_type = BtfType::Const(Const::new(ty.btf_type)); *t = BtfType::Const(Const::new(ty.btf_type));
types.types[i] = const_type;
} }
// Sanitize Signed ENUMs. // Sanitize Signed ENUMs.
BtfType::Enum(ty) if !features.btf_enum64 && ty.is_signed() => { BtfType::Enum(ty) if !features.btf_enum64 && ty.is_signed() => {
@ -715,9 +714,7 @@ impl Btf {
offset: 0, offset: 0,
}) })
.collect(); .collect();
let union_type = *t = BtfType::Union(Union::new(ty.name_offset, members.len() as u32, members));
BtfType::Union(Union::new(ty.name_offset, members.len() as u32, members));
types.types[i] = union_type;
} }
// The type does not need fixing up or sanitization. // The type does not need fixing up or sanitization.
_ => {} _ => {}

Loading…
Cancel
Save