Add wrapper to prevent iteration of unordered maps
diff --git a/gen/build/src/cfg.rs b/gen/build/src/cfg.rs
index c15a173..6818bda 100644
--- a/gen/build/src/cfg.rs
+++ b/gen/build/src/cfg.rs
@@ -266,10 +266,10 @@
#[cfg(not(doc))]
mod r#impl {
use crate::intern::{intern, InternedString};
+ use crate::syntax::map::UnorderedMap as Map;
use crate::vec::{self, InternedVec as _};
use lazy_static::lazy_static;
use std::cell::RefCell;
- use std::collections::HashMap;
use std::fmt::{self, Debug};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
@@ -316,7 +316,7 @@
// cfg: AtomicPtr<super::Cfg>,
// }
//
- static CONST_DEREFS: RefCell<HashMap<Handle, Box<super::Cfg<'static>>>> = RefCell::default();
+ static CONST_DEREFS: RefCell<Map<Handle, Box<super::Cfg<'static>>>> = RefCell::default();
}
#[derive(Eq, PartialEq, Hash)]
diff --git a/gen/build/src/intern.rs b/gen/build/src/intern.rs
index 51bc07c..25b8706 100644
--- a/gen/build/src/intern.rs
+++ b/gen/build/src/intern.rs
@@ -1,5 +1,5 @@
+use crate::syntax::set::UnorderedSet as Set;
use lazy_static::lazy_static;
-use std::collections::HashSet;
use std::sync::{Mutex, PoisonError};
#[derive(Copy, Clone, Default)]
@@ -13,7 +13,7 @@
pub fn intern(s: &str) -> InternedString {
lazy_static! {
- static ref INTERN: Mutex<HashSet<&'static str>> = Mutex::new(HashSet::new());
+ static ref INTERN: Mutex<Set<&'static str>> = Mutex::new(Set::new());
}
let mut set = INTERN.lock().unwrap_or_else(PoisonError::into_inner);
diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs
index f7d4182..204c89f 100644
--- a/gen/build/src/lib.rs
+++ b/gen/build/src/lib.rs
@@ -90,10 +90,10 @@
use crate::gen::error::report;
use crate::gen::Opt;
use crate::paths::PathExt;
+use crate::syntax::map::{Entry, UnorderedMap};
use crate::target::TargetDir;
use cc::Build;
-use std::collections::btree_map::Entry;
-use std::collections::{BTreeMap, BTreeSet};
+use std::collections::BTreeSet;
use std::env;
use std::ffi::{OsStr, OsString};
use std::io::{self, Write};
@@ -288,7 +288,7 @@
});
}
- let mut header_dirs_index = BTreeMap::new();
+ let mut header_dirs_index = UnorderedMap::new();
let mut used_header_links = BTreeSet::new();
let mut used_header_prefixes = BTreeSet::new();
for krate in deps::direct_dependencies() {
diff --git a/gen/src/nested.rs b/gen/src/nested.rs
index d94d36d..c030717 100644
--- a/gen/src/nested.rs
+++ b/gen/src/nested.rs
@@ -1,6 +1,6 @@
+use crate::syntax::map::UnorderedMap as Map;
use crate::syntax::Api;
use proc_macro2::Ident;
-use std::collections::HashMap as Map;
pub struct NamespaceEntries<'a> {
direct: Vec<&'a Api>,
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 8242b2e..d2dbe02 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -3,6 +3,8 @@
use crate::gen::out::OutFile;
use crate::gen::{builtin, include, Opt};
use crate::syntax::atom::Atom::{self, *};
+use crate::syntax::map::UnorderedMap as Map;
+use crate::syntax::set::UnorderedSet;
use crate::syntax::symbol::Symbol;
use crate::syntax::trivial::{self, TrivialReason};
use crate::syntax::{
@@ -10,7 +12,6 @@
Type, TypeAlias, Types, Var,
};
use proc_macro2::Ident;
-use std::collections::{HashMap, HashSet};
pub(super) fn gen(apis: &[Api], types: &Types, opt: &Opt, header: bool) -> Vec<u8> {
let mut out_file = OutFile::new(header, opt, types);
@@ -65,7 +66,7 @@
}
fn write_data_structures<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) {
- let mut methods_for_type = HashMap::new();
+ let mut methods_for_type = Map::new();
for api in apis {
if let Api::CxxFunction(efn) | Api::RustFunction(efn) = api {
if let Some(receiver) = &efn.sig.receiver {
@@ -77,7 +78,7 @@
}
}
- let mut structs_written = HashSet::new();
+ let mut structs_written = UnorderedSet::new();
let mut toposorted_structs = out.types.toposorted_structs.iter();
for api in apis {
match api {