Reduce usage of Default::default()

This commit is contained in:
Stephen Chung
2021-09-11 19:40:40 +08:00
parent 5d3a22ab6f
commit 6510b617fe
14 changed files with 59 additions and 45 deletions

View File

@@ -142,7 +142,7 @@ impl<'d> Visitor<'d> for DynamicVisitor {
#[cfg(not(feature = "no_index"))]
fn visit_seq<A: SeqAccess<'d>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let mut arr: Array = Default::default();
let mut arr = Array::new();
while let Some(v) = seq.next_element()? {
arr.push(v);
@@ -153,7 +153,7 @@ impl<'d> Visitor<'d> for DynamicVisitor {
#[cfg(not(feature = "no_object"))]
fn visit_map<M: MapAccess<'d>>(self, mut map: M) -> Result<Self::Value, M::Error> {
let mut m: Map = Default::default();
let mut m = Map::new();
while let Some((k, v)) = map.next_entry::<&str, _>()? {
m.insert(k.into(), v);

View File

@@ -207,6 +207,13 @@ struct ModuleMetadata {
pub functions: Vec<FnMetadata>,
}
impl ModuleMetadata {
#[inline(always)]
pub fn new() -> Self {
Default::default()
}
}
impl From<&crate::Module> for ModuleMetadata {
fn from(module: &crate::Module) -> Self {
let mut functions: Vec<_> = module.iter_fn().map(|f| f.into()).collect();
@@ -239,7 +246,7 @@ impl Engine {
include_global: bool,
) -> serde_json::Result<String> {
let _ast = ast;
let mut global: ModuleMetadata = Default::default();
let mut global = ModuleMetadata::new();
if include_global {
self.global_modules