Skip to content

Commit 1104631

Browse files
authored
Merge pull request #1473 from emilio/hash
Some perf tweaks
2 parents f2ac19c + 2c8bf0b commit 1104631

20 files changed

+162
-142
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ peeking_take_while = "0.1.2"
5454
quote = { version = "0.6", default-features = false }
5555
regex = "1.0"
5656
which = "2.0"
57+
hashbrown = "0.1"
5758
# New validation in 0.3.6 breaks bindgen-integration:
5859
# https://github.com/alexcrichton/proc-macro2/commit/489c642.
5960
proc-macro2 = { version = "0.4", default-features = false }

src/codegen/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ use proc_macro2::{self, Ident, Span};
4343
use std;
4444
use std::borrow::Cow;
4545
use std::cell::Cell;
46-
use std::collections::{HashSet, VecDeque};
47-
use std::collections::hash_map::{Entry, HashMap};
46+
use std::collections::VecDeque;
4847
use std::fmt::Write;
4948
use std::iter;
5049
use std::ops;
5150
use std::str::FromStr;
51+
use {HashMap, HashSet, Entry};
5252

5353
// Name of type defined in constified enum module
5454
pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &'static str = "Type";
@@ -2638,7 +2638,7 @@ impl CodeGenerator for Enum {
26382638
);
26392639

26402640
// A map where we keep a value -> variant relation.
2641-
let mut seen_values = HashMap::<_, Ident>::new();
2641+
let mut seen_values = HashMap::<_, Ident>::default();
26422642
let enum_rust_ty = item.to_rust_ty_or_opaque(ctx, &());
26432643
let is_toplevel = item.is_toplevel(ctx);
26442644

@@ -3546,11 +3546,12 @@ pub(crate) fn codegen(context: BindgenContext) -> (Vec<proc_macro2::TokenStream>
35463546

35473547
debug!("codegen: {:?}", context.options());
35483548

3549-
let codegen_items = context.codegen_items();
35503549
if context.options().emit_ir {
3551-
for &id in codegen_items {
3552-
let item = context.resolve_item(id);
3553-
println!("ir: {:?} = {:#?}", id, item);
3550+
let codegen_items = context.codegen_items();
3551+
for (id, item) in context.items() {
3552+
if codegen_items.contains(&id) {
3553+
println!("ir: {:?} = {:#?}", id, item);
3554+
}
35543555
}
35553556
}
35563557

src/ir/analysis/derive_copy.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use ir::template::TemplateParameters;
1111
use ir::traversal::EdgeKind;
1212
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1313
use ir::ty::TypeKind;
14-
use std::collections::HashMap;
15-
use std::collections::HashSet;
14+
use {HashMap, HashSet};
1615

1716
/// An analysis that finds for each IR item whether copy cannot be derived.
1817
///
@@ -103,7 +102,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
103102
type Output = HashSet<ItemId>;
104103

105104
fn new(ctx: &'ctx BindgenContext) -> CannotDeriveCopy<'ctx> {
106-
let cannot_derive_copy = HashSet::new();
105+
let cannot_derive_copy = HashSet::default();
107106
let dependencies = generate_dependencies(ctx, Self::consider_edge);
108107

109108
CannotDeriveCopy {

src/ir/analysis/derive_debug.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use ir::item::IsOpaque;
1010
use ir::traversal::EdgeKind;
1111
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1212
use ir::ty::TypeKind;
13-
use std::collections::HashMap;
14-
use std::collections::HashSet;
13+
use {HashMap, HashSet};
1514

1615
/// An analysis that finds for each IR item whether debug cannot be derived.
1716
///
@@ -104,7 +103,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
104103
type Output = HashSet<ItemId>;
105104

106105
fn new(ctx: &'ctx BindgenContext) -> CannotDeriveDebug<'ctx> {
107-
let cannot_derive_debug = HashSet::new();
106+
let cannot_derive_debug = HashSet::default();
108107
let dependencies = generate_dependencies(ctx, Self::consider_edge);
109108

110109
CannotDeriveDebug {

src/ir/analysis/derive_default.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use ir::traversal::EdgeKind;
1212
use ir::traversal::Trace;
1313
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1414
use ir::ty::TypeKind;
15-
use std::collections::HashMap;
16-
use std::collections::HashSet;
15+
use {HashMap, HashSet};
1716

1817
/// An analysis that finds for each IR item whether default cannot be derived.
1918
///
@@ -99,8 +98,8 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
9998
type Output = HashSet<ItemId>;
10099

101100
fn new(ctx: &'ctx BindgenContext) -> CannotDeriveDefault<'ctx> {
102-
let mut dependencies = HashMap::new();
103-
let cannot_derive_default = HashSet::new();
101+
let mut dependencies = HashMap::default();
102+
let cannot_derive_default = HashSet::default();
104103

105104
let whitelisted_items: HashSet<_> =
106105
ctx.whitelisted_items().iter().cloned().collect();

src/ir/analysis/derive_hash.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use ir::item::IsOpaque;
1010
use ir::traversal::EdgeKind;
1111
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1212
use ir::ty::TypeKind;
13-
use std::collections::HashMap;
14-
use std::collections::HashSet;
13+
use {HashMap, HashSet};
1514

1615
/// An analysis that finds for each IR item whether hash cannot be derived.
1716
///
@@ -96,7 +95,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
9695
type Output = HashSet<ItemId>;
9796

9897
fn new(ctx: &'ctx BindgenContext) -> CannotDeriveHash<'ctx> {
99-
let cannot_derive_hash = HashSet::new();
98+
let cannot_derive_hash = HashSet::default();
10099
let dependencies = generate_dependencies(ctx, Self::consider_edge);
101100

102101
CannotDeriveHash {

src/ir/analysis/derive_partialeq_or_partialord.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use ir::item::{Item, IsOpaque};
99
use ir::traversal::{EdgeKind, Trace};
1010
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1111
use ir::ty::{TypeKind, Type};
12-
use std::collections::HashMap;
13-
use std::collections::hash_map::Entry;
12+
use {HashMap, Entry};
1413

1514
/// An analysis that finds for each IR item whether `PartialEq`/`PartialOrd`
1615
/// cannot be derived.
@@ -326,7 +325,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
326325
fn new(
327326
ctx: &'ctx BindgenContext,
328327
) -> CannotDerivePartialEqOrPartialOrd<'ctx> {
329-
let can_derive_partialeq_or_partialord = HashMap::new();
328+
let can_derive_partialeq_or_partialord = HashMap::default();
330329
let dependencies = generate_dependencies(ctx, Self::consider_edge);
331330

332331
CannotDerivePartialEqOrPartialOrd {

src/ir/analysis/has_destructor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use ir::context::{BindgenContext, ItemId};
55
use ir::traversal::EdgeKind;
66
use ir::comp::{CompKind, Field, FieldMethods};
77
use ir::ty::TypeKind;
8-
use std::collections::HashMap;
9-
use std::collections::HashSet;
8+
use {HashMap, HashSet};
109

1110
/// An analysis that finds for each IR item whether it has a destructor or not
1211
///
@@ -73,7 +72,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> {
7372
type Output = HashSet<ItemId>;
7473

7574
fn new(ctx: &'ctx BindgenContext) -> Self {
76-
let have_destructor = HashSet::new();
75+
let have_destructor = HashSet::default();
7776
let dependencies = generate_dependencies(ctx, Self::consider_edge);
7877

7978
HasDestructorAnalysis {

src/ir/analysis/has_float.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Determining which types has float.
22
33
use super::{ConstrainResult, MonotoneFramework, generate_dependencies};
4-
use std::collections::HashSet;
5-
use std::collections::HashMap;
4+
use {HashSet, HashMap};
65
use ir::context::{BindgenContext, ItemId};
76
use ir::traversal::EdgeKind;
87
use ir::ty::TypeKind;
@@ -84,7 +83,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> {
8483
type Output = HashSet<ItemId>;
8584

8685
fn new(ctx: &'ctx BindgenContext) -> HasFloat<'ctx> {
87-
let has_float = HashSet::new();
86+
let has_float = HashSet::default();
8887
let dependencies = generate_dependencies(ctx, Self::consider_edge);
8988

9089
HasFloat {

0 commit comments

Comments
 (0)