Change HashMap to BTreeMap.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#![cfg(not(feature = "no_index"))]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::engine::{OP_EQUALS, TYPICAL_ARRAY_SIZE};
|
||||
use crate::engine::OP_EQUALS;
|
||||
use crate::plugin::*;
|
||||
use crate::stdlib::{any::TypeId, boxed::Box, cmp::max, cmp::Ordering, mem, string::ToString};
|
||||
use crate::stdlib::{any::TypeId, boxed::Box, cmp::Ordering, mem, string::ToString};
|
||||
use crate::{def_package, Array, Dynamic, EvalAltResult, FnPtr, NativeCallContext, Position, INT};
|
||||
|
||||
def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
|
||||
@@ -170,7 +170,7 @@ mod array_functions {
|
||||
array: &mut Array,
|
||||
mapper: FnPtr,
|
||||
) -> Result<Array, Box<EvalAltResult>> {
|
||||
let mut ar = Array::with_capacity(max(TYPICAL_ARRAY_SIZE, array.len()));
|
||||
let mut ar = Array::with_capacity(array.len());
|
||||
|
||||
for (i, item) in array.iter().enumerate() {
|
||||
ar.push(
|
||||
@@ -203,7 +203,7 @@ mod array_functions {
|
||||
array: &mut Array,
|
||||
filter: FnPtr,
|
||||
) -> Result<Array, Box<EvalAltResult>> {
|
||||
let mut ar = Array::with_capacity(max(TYPICAL_ARRAY_SIZE, array.len()));
|
||||
let mut ar = Array::new();
|
||||
|
||||
for (i, item) in array.iter().enumerate() {
|
||||
if filter
|
||||
@@ -565,7 +565,7 @@ mod array_functions {
|
||||
array: &mut Array,
|
||||
filter: FnPtr,
|
||||
) -> Result<Array, Box<EvalAltResult>> {
|
||||
let mut drained = Array::with_capacity(max(TYPICAL_ARRAY_SIZE, array.len()));
|
||||
let mut drained = Array::with_capacity(array.len());
|
||||
|
||||
let mut i = array.len();
|
||||
|
||||
@@ -625,7 +625,7 @@ mod array_functions {
|
||||
array: &mut Array,
|
||||
filter: FnPtr,
|
||||
) -> Result<Array, Box<EvalAltResult>> {
|
||||
let mut drained = Array::with_capacity(max(TYPICAL_ARRAY_SIZE, array.len()));
|
||||
let mut drained = Array::new();
|
||||
|
||||
let mut i = array.len();
|
||||
|
||||
|
@@ -34,34 +34,34 @@ mod fn_ptr_functions {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
use crate::{ast::ScriptFnDef, stdlib::collections::HashMap, Array, Map};
|
||||
use crate::{ast::ScriptFnDef, stdlib::collections::BTreeSet, Array, Map};
|
||||
|
||||
// Create a metadata record for a function.
|
||||
fn make_metadata(
|
||||
dict: &HashMap<&str, ImmutableString>,
|
||||
dict: &BTreeSet<ImmutableString>,
|
||||
namespace: Option<ImmutableString>,
|
||||
f: &ScriptFnDef,
|
||||
) -> Map {
|
||||
let mut map = Map::with_capacity(6);
|
||||
let mut map = Map::new();
|
||||
|
||||
if let Some(ns) = namespace {
|
||||
map.insert(dict["namespace"].clone(), ns.into());
|
||||
map.insert(dict.get("namespace").unwrap().clone(), ns.into());
|
||||
}
|
||||
map.insert(dict["name"].clone(), f.name.clone().into());
|
||||
map.insert(dict.get("name").unwrap().clone(), f.name.clone().into());
|
||||
map.insert(
|
||||
dict["access"].clone(),
|
||||
dict.get("access").unwrap().clone(),
|
||||
match f.access {
|
||||
FnAccess::Public => dict["public"].clone(),
|
||||
FnAccess::Private => dict["private"].clone(),
|
||||
FnAccess::Public => dict.get("public").unwrap().clone(),
|
||||
FnAccess::Private => dict.get("private").unwrap().clone(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
map.insert(
|
||||
dict["is_anonymous"].clone(),
|
||||
dict.get("is_anonymous").unwrap().clone(),
|
||||
f.name.starts_with(crate::engine::FN_ANONYMOUS).into(),
|
||||
);
|
||||
map.insert(
|
||||
dict["params"].clone(),
|
||||
dict.get("params").unwrap().clone(),
|
||||
f.params
|
||||
.iter()
|
||||
.cloned()
|
||||
@@ -74,8 +74,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
}
|
||||
|
||||
// Intern strings
|
||||
let mut dict = HashMap::<&str, ImmutableString>::with_capacity(8);
|
||||
[
|
||||
let dict: BTreeSet<ImmutableString> = [
|
||||
"namespace",
|
||||
"name",
|
||||
"access",
|
||||
@@ -85,9 +84,8 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
"params",
|
||||
]
|
||||
.iter()
|
||||
.for_each(|&s| {
|
||||
dict.insert(s, s.into());
|
||||
});
|
||||
.map(|&s| s.into())
|
||||
.collect();
|
||||
|
||||
let mut list: Array = Default::default();
|
||||
|
||||
@@ -100,7 +98,7 @@ fn collect_fn_metadata(ctx: NativeCallContext) -> crate::Array {
|
||||
// Recursively scan modules for script-defined functions.
|
||||
fn scan_module(
|
||||
list: &mut Array,
|
||||
dict: &HashMap<&str, ImmutableString>,
|
||||
dict: &BTreeSet<ImmutableString>,
|
||||
namespace: ImmutableString,
|
||||
module: &Module,
|
||||
) {
|
||||
|
@@ -89,7 +89,7 @@ macro_rules! def_package {
|
||||
|
||||
impl $package {
|
||||
pub fn new() -> Self {
|
||||
let mut module = $root::Module::new_with_capacity(1024);
|
||||
let mut module = $root::Module::new();
|
||||
<Self as $root::packages::Package>::init(&mut module);
|
||||
module.build_index();
|
||||
Self(module.into())
|
||||
|
Reference in New Issue
Block a user