diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-10-11 18:00:29 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-10-11 18:17:09 +0200 |
commit | 6055f364bd1d341da8fa881741ec36ab0abf0a7a (patch) | |
tree | 1c931e49d9fd88a11a662d86799e6be7a67c9f86 | |
parent | c137196c9f4411456284e2205db314a4ae700f9f (diff) |
Minor cleanup after #1419.v0.42.2
The previous PR ended up with a lot of just-called-once methods. Just inline
them since they're confusing otherwise.
Also avoid testing all the variants of an enum if there was a match already, or
if the enum is not anonymous. This is mostly a minor optimization.
-rw-r--r-- | src/ir/enum_ty.rs | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 6d1e7214..f3da2199 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -143,46 +143,29 @@ impl Enum { let path = item.canonical_path(ctx); let enum_ty = item.expect_type(); - let path_matches = enums.matches(&path[1..].join("::")); - let enum_is_anon = enum_ty.name().is_none(); - let a_variant_matches = self.variants().iter().any(|v| { - enums.matches(&v.name()) - }); - path_matches || (enum_is_anon && a_variant_matches) - } - - /// Whether the enum was explicitly specified to be a bitfield. - fn is_bitfield(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().bitfield_enums, item) - } - - /// Whether the enum was explicitly specified to be an constified enum - /// module. - fn is_constified_enum_module(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().constified_enum_modules, item) - } + if enums.matches(&path[1..].join("::")) { + return true; + } - /// Whether the enum was explicitly specified to be an set of constants. - fn is_constified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().constified_enums, item) - } + // Test the variants if the enum is anonymous. + if enum_ty.name().is_some() { + return false; + } - /// Whether the enum was explicitly specified to be a Rust enum. - fn is_rustified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().rustified_enums, item) + self.variants().iter().any(|v| enums.matches(&v.name())) } /// Returns the final representation of the enum. pub fn computed_enum_variation(&self, ctx: &BindgenContext, item: &Item) -> EnumVariation { // ModuleConsts has higher precedence before Rust in order to avoid // problems with overlapping match patterns. - if self.is_constified_enum_module(ctx, item) { + if self.is_matching_enum(ctx, &ctx.options().constified_enum_modules, item) { EnumVariation::ModuleConsts - } else if self.is_bitfield(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().bitfield_enums, item) { EnumVariation::Bitfield - } else if self.is_rustified_enum(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().rustified_enums, item) { EnumVariation::Rust - } else if self.is_constified_enum(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().constified_enums, item) { EnumVariation::Consts } else { ctx.options().default_enum_style |