Use BTreeMap only where absolutely necessary
This commit is contained in:
parent
ede9ed68e0
commit
23cbec85e9
|
@ -14,7 +14,7 @@ use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
|
|||
use itertools::Itertools;
|
||||
use proc_macro2::Term;
|
||||
use quote::Tokens;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::path::Path;
|
||||
use syn::Ident;
|
||||
pub trait ExtensionExt {}
|
||||
|
@ -681,12 +681,12 @@ impl FieldExt for vkxml::Field {
|
|||
}
|
||||
}
|
||||
|
||||
pub type CommandMap<'a> = BTreeMap<vkxml::Identifier, &'a vkxml::Command>;
|
||||
pub type CommandMap<'a> = HashMap<vkxml::Identifier, &'a vkxml::Command>;
|
||||
|
||||
fn generate_function_pointers<'a>(
|
||||
ident: Ident,
|
||||
commands: &[&'a vkxml::Command],
|
||||
fn_cache: &mut BTreeSet<&'a str>,
|
||||
fn_cache: &mut HashSet<&'a str>,
|
||||
) -> quote::Tokens {
|
||||
let names: Vec<_> = commands.iter().map(|cmd| cmd.command_ident()).collect();
|
||||
let names_ref = &names;
|
||||
|
@ -874,7 +874,7 @@ pub fn generate_extension_constants<'a>(
|
|||
extension_name: &str,
|
||||
extension_number: i64,
|
||||
extension_items: &'a [vk_parse::ExtensionChild],
|
||||
const_cache: &mut BTreeSet<&'a str>,
|
||||
const_cache: &mut HashSet<&'a str>,
|
||||
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
|
||||
) -> quote::Tokens {
|
||||
use vk_parse::EnumSpec;
|
||||
|
@ -939,7 +939,7 @@ pub fn generate_extension_commands<'a>(
|
|||
extension_name: &str,
|
||||
items: &[vk_parse::ExtensionChild],
|
||||
cmd_map: &CommandMap<'a>,
|
||||
fn_cache: &mut BTreeSet<&'a str>,
|
||||
fn_cache: &mut HashSet<&'a str>,
|
||||
) -> Tokens {
|
||||
let commands = items
|
||||
.iter()
|
||||
|
@ -978,9 +978,9 @@ pub fn generate_extension_commands<'a>(
|
|||
pub fn generate_extension<'a>(
|
||||
extension: &'a vk_parse::Extension,
|
||||
cmd_map: &CommandMap<'a>,
|
||||
const_cache: &mut BTreeSet<&'a str>,
|
||||
const_cache: &mut HashSet<&'a str>,
|
||||
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
|
||||
fn_cache: &mut BTreeSet<&'a str>,
|
||||
fn_cache: &mut HashSet<&'a str>,
|
||||
) -> Option<quote::Tokens> {
|
||||
// Okay this is a little bit odd. We need to generate all extensions, even disabled ones,
|
||||
// because otherwise some StructureTypes won't get generated. But we don't generate extensions
|
||||
|
@ -1011,7 +1011,7 @@ pub fn generate_typedef(typedef: &vkxml::Typedef) -> Tokens {
|
|||
}
|
||||
pub fn generate_bitmask(
|
||||
bitmask: &vkxml::Bitmask,
|
||||
bitflags_cache: &mut BTreeSet<Ident>,
|
||||
bitflags_cache: &mut HashSet<Ident>,
|
||||
) -> Option<Tokens> {
|
||||
// Workaround for empty bitmask
|
||||
if bitmask.name.is_empty() {
|
||||
|
@ -1113,9 +1113,9 @@ pub fn bitflags_impl_block(
|
|||
|
||||
pub fn generate_enum<'a>(
|
||||
_enum: &'a vkxml::Enumeration,
|
||||
const_cache: &mut BTreeSet<&'a str>,
|
||||
const_cache: &mut HashSet<&'a str>,
|
||||
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
|
||||
bitflags_cache: &mut BTreeSet<Ident>,
|
||||
bitflags_cache: &mut HashSet<Ident>,
|
||||
) -> EnumType {
|
||||
let name = &_enum.name[2..];
|
||||
let _name = name.replace("FlagBits", "Flags");
|
||||
|
@ -1328,7 +1328,7 @@ pub fn derive_default(_struct: &vkxml::Struct) -> Option<Tokens> {
|
|||
};
|
||||
Some(q)
|
||||
}
|
||||
pub fn derive_debug(_struct: &vkxml::Struct, union_types: &BTreeSet<&str>) -> Option<Tokens> {
|
||||
pub fn derive_debug(_struct: &vkxml::Struct, union_types: &HashSet<&str>) -> Option<Tokens> {
|
||||
let name = name_to_tokens(&_struct.name);
|
||||
let members = _struct.elements.iter().filter_map(|elem| match *elem {
|
||||
vkxml::StructElement::Member(ref field) => Some(field),
|
||||
|
@ -1389,7 +1389,7 @@ pub fn derive_debug(_struct: &vkxml::Struct, union_types: &BTreeSet<&str>) -> Op
|
|||
|
||||
pub fn derive_setters(
|
||||
_struct: &vkxml::Struct,
|
||||
root_struct_names: &BTreeSet<String>,
|
||||
root_struct_names: &HashSet<String>,
|
||||
) -> Option<Tokens> {
|
||||
if &_struct.name == "VkBaseInStructure" || &_struct.name == "VkBaseOutStructure" {
|
||||
return None;
|
||||
|
@ -1716,8 +1716,8 @@ pub fn manual_derives(_struct: &vkxml::Struct) -> Tokens {
|
|||
}
|
||||
pub fn generate_struct(
|
||||
_struct: &vkxml::Struct,
|
||||
root_struct_names: &BTreeSet<String>,
|
||||
union_types: &BTreeSet<&str>,
|
||||
root_struct_names: &HashSet<String>,
|
||||
union_types: &HashSet<&str>,
|
||||
) -> Tokens {
|
||||
let name = name_to_tokens(&_struct.name);
|
||||
let members = _struct.elements.iter().filter_map(|elem| match *elem {
|
||||
|
@ -1819,7 +1819,7 @@ fn generate_union(union: &vkxml::Union) -> Tokens {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub fn root_struct_names(definitions: &[&vkxml::DefinitionsElement]) -> BTreeSet<String> {
|
||||
pub fn root_struct_names(definitions: &[&vkxml::DefinitionsElement]) -> HashSet<String> {
|
||||
definitions
|
||||
.iter()
|
||||
.filter_map(|definition| match *definition {
|
||||
|
@ -1837,9 +1837,9 @@ pub fn root_struct_names(definitions: &[&vkxml::DefinitionsElement]) -> BTreeSet
|
|||
}
|
||||
pub fn generate_definition(
|
||||
definition: &vkxml::DefinitionsElement,
|
||||
union_types: &BTreeSet<&str>,
|
||||
root_structs: &BTreeSet<String>,
|
||||
bitflags_cache: &mut BTreeSet<Ident>,
|
||||
union_types: &HashSet<&str>,
|
||||
root_structs: &HashSet<String>,
|
||||
bitflags_cache: &mut HashSet<Ident>,
|
||||
) -> Option<Tokens> {
|
||||
match *definition {
|
||||
vkxml::DefinitionsElement::Typedef(ref typedef) => Some(generate_typedef(typedef)),
|
||||
|
@ -1856,7 +1856,7 @@ pub fn generate_definition(
|
|||
pub fn generate_feature<'a>(
|
||||
feature: &vkxml::Feature,
|
||||
commands: &CommandMap<'a>,
|
||||
fn_cache: &mut BTreeSet<&'a str>,
|
||||
fn_cache: &mut HashSet<&'a str>,
|
||||
) -> quote::Tokens {
|
||||
let (static_commands, entry_commands, device_commands, instance_commands) = feature
|
||||
.elements
|
||||
|
@ -1933,7 +1933,7 @@ pub fn constant_name(name: &str) -> String {
|
|||
|
||||
pub fn generate_constant<'a>(
|
||||
constant: &'a vkxml::Constant,
|
||||
cache: &mut BTreeSet<&'a str>,
|
||||
cache: &mut HashSet<&'a str>,
|
||||
) -> Tokens {
|
||||
cache.insert(constant.name.as_str());
|
||||
let c = Constant::from_constant(constant);
|
||||
|
@ -1953,7 +1953,7 @@ pub fn generate_constant<'a>(
|
|||
|
||||
pub fn generate_feature_extension<'a>(
|
||||
registry: &'a vk_parse::Registry,
|
||||
const_cache: &mut BTreeSet<&'a str>,
|
||||
const_cache: &mut HashSet<&'a str>,
|
||||
const_values: &mut BTreeMap<Ident, Vec<Ident>>,
|
||||
) -> Tokens {
|
||||
let constants = registry.0.iter().filter_map(|item| match item {
|
||||
|
@ -2035,7 +2035,7 @@ pub fn generate_const_displays<'a>(const_values: &BTreeMap<Ident, Vec<Ident>>) -
|
|||
}
|
||||
pub fn generate_aliases_of_types<'a>(
|
||||
types: &'a vk_parse::Types,
|
||||
ty_cache: &mut BTreeSet<Ident>,
|
||||
ty_cache: &mut HashSet<Ident>,
|
||||
) -> Tokens {
|
||||
let aliases = types
|
||||
.children
|
||||
|
@ -2073,7 +2073,7 @@ pub fn write_source_code(path: &Path) {
|
|||
})
|
||||
.nth(0)
|
||||
.expect("extension");
|
||||
let mut ty_cache = BTreeSet::new();
|
||||
let mut ty_cache = HashSet::new();
|
||||
let aliases: Vec<_> = spec2
|
||||
.0
|
||||
.iter()
|
||||
|
@ -2086,7 +2086,7 @@ pub fn write_source_code(path: &Path) {
|
|||
.collect();
|
||||
|
||||
let spec = vk_parse::parse_file_as_vkxml(path);
|
||||
let commands: BTreeMap<vkxml::Identifier, &vkxml::Command> = spec
|
||||
let commands: HashMap<vkxml::Identifier, &vkxml::Command> = spec
|
||||
.elements
|
||||
.iter()
|
||||
.filter_map(|elem| match elem {
|
||||
|
@ -2141,9 +2141,9 @@ pub fn write_source_code(path: &Path) {
|
|||
.flat_map(|constants| constants.elements.iter())
|
||||
.collect();
|
||||
|
||||
let mut fn_cache = BTreeSet::new();
|
||||
let mut bitflags_cache = BTreeSet::new();
|
||||
let mut const_cache = BTreeSet::new();
|
||||
let mut fn_cache = HashSet::new();
|
||||
let mut bitflags_cache = HashSet::new();
|
||||
let mut const_cache = HashSet::new();
|
||||
|
||||
let mut const_values: BTreeMap<Ident, Vec<Ident>> = BTreeMap::new();
|
||||
|
||||
|
@ -2181,7 +2181,7 @@ pub fn write_source_code(path: &Path) {
|
|||
vkxml::DefinitionsElement::Union(ref union) => Some(union.name.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<BTreeSet<&str>>();
|
||||
.collect::<HashSet<&str>>();
|
||||
|
||||
let root_names = root_struct_names(&definitions);
|
||||
let definition_code: Vec<_> = definitions
|
||||
|
|
Loading…
Reference in a new issue