difftreelog
perf destruct capacity hints
in: master
2 files changed
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth44 args: &dyn ArgsLike,44 args: &dyn ArgsLike,45 tailstrict: bool,45 tailstrict: bool,46) -> Result<Context> {46) -> Result<Context> {47 let mut passed_args = GcHashMap::with_capacity(params.len());47 let mut passed_args =48 GcHashMap::with_capacity(params.iter().map(|p| p.0.capacity_hint()).sum());48 if args.unnamed_len() > params.len() {49 if args.unnamed_len() > params.len() {49 throw!(TooManyArgsFunctionHas(50 throw!(TooManyArgsFunctionHas(50 params.len(),51 params.len(),84 // Default values should be created in newly created context85 // Default values should be created in newly created context85 let fctx = Context::new_future();86 let fctx = Context::new_future();86 let mut defaults =87 let mut defaults = GcHashMap::with_capacity(87 GcHashMap::with_capacity(params.len() - filled_named - filled_positionals);88 params.iter().map(|p| p.0.capacity_hint()).sum::<usize>()89 - filled_named - filled_positionals,90 );8891241244242 let fctx = Context::new_future();245 let fctx = Context::new_future();243246244 let mut bindings = GcHashMap::new();247 let mut bindings = GcHashMap::with_capacity(params.iter().map(|p| p.0.capacity_hint()).sum());245248246 for param in params.iter() {249 for param in params.iter() {247 if let Some(v) = ¶m.1 {250 if let Some(v) = ¶m.1 {crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth228 _ => None,228 _ => None,229 }229 }230 }230 }231 pub fn capacity_hint(&self) -> usize {232 #[cfg(feature = "exp-destruct")]233 fn cap_rest(rest: &Option<DestructRest>) -> usize {234 match rest {235 Some(DestructRest::Keep(_)) => 1,236 Some(DestructRest::Drop) => 0,237 None => 0,238 }239 }240 match self {241 Self::Full(_) => 1,242 #[cfg(feature = "exp-destruct")]243 Self::Skip => 0,244 #[cfg(feature = "exp-destruct")]245 Self::Array { start, rest, end } => {246 start.iter().map(Destruct::capacity_hint).sum::<usize>()247 + end.iter().map(Destruct::capacity_hint).sum::<usize>()248 + cap_rest(rest)249 }250 #[cfg(feature = "exp-destruct")]251 Self::Object { fields, rest } => {252 let mut out = 0;253 for (_, into, _) in fields {254 match into {255 Some(v) => out += v.capacity_hint(),256 // Field is destructured to default name257 None => out += 1,258 }259 }260 out + cap_rest(rest)261 }262 }263 }231}264}232265233#[cfg_attr(feature = "structdump", derive(Codegen))]266#[cfg_attr(feature = "structdump", derive(Codegen))]244 value: LocExpr,277 value: LocExpr,245 },278 },246}279}280impl BindSpec {281 pub fn capacity_hint(&self) -> usize {282 match self {283 BindSpec::Field { into, .. } => into.capacity_hint(),284 BindSpec::Function { .. } => 1,285 }286 }287}247288248#[cfg_attr(feature = "structdump", derive(Codegen))]289#[cfg_attr(feature = "structdump", derive(Codegen))]249#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]290#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]