Implement conversion from IceResult into BreadcrumbTreeNode.
I believe this change will remove an extra heap allocation I was doing in the new_breadcrumbs_* functions for the explicit context by adding support for converting from Rc<dyn ContextElement> to Rc<dyn IntoContextElement> without copying the underlying data. This should allow conversion of the IceResult::Owned variant to the BreadcrumbTreeElement::Owned variant without extra copying.
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::parser::KVPair;
|
||||
use crate::parser::OwnedLiteral;
|
||||
use crate::parser::RValue;
|
||||
use crate::renderer::breadcrumb_tree::BreadcrumbTree;
|
||||
use crate::renderer::breadcrumb_tree::BreadcrumbTreeElement;
|
||||
use crate::renderer::context_element::CompareContextElement;
|
||||
use crate::renderer::context_element::ContextElement;
|
||||
use crate::renderer::context_element::IceResult;
|
||||
@@ -21,7 +22,7 @@ use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParametersContext<'a> {
|
||||
params: HashMap<&'a str, &'a dyn IntoContextElement>,
|
||||
params: HashMap<&'a str, BreadcrumbTreeElement<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> ParametersContext<'a> {
|
||||
@@ -38,12 +39,14 @@ impl<'a> ParametersContext<'a> {
|
||||
// then those are resolved at the time of access rather than
|
||||
// the time of assignment, so we leave them into their
|
||||
// original IntoContextElement state.
|
||||
let rendered_params = params
|
||||
let rendered_params: HashMap<&'a str, BreadcrumbTreeElement<'a>> = params
|
||||
.iter()
|
||||
.map(|kvpair| {
|
||||
let k = kvpair.key;
|
||||
let v: &dyn IntoContextElement = match &kvpair.value {
|
||||
RValue::RVLiteral(owned_literal) => &kvpair.value,
|
||||
let v: BreadcrumbTreeElement<'a> = match &kvpair.value {
|
||||
RValue::RVLiteral(owned_literal) => {
|
||||
BreadcrumbTreeElement::Borrowed(&kvpair.value)
|
||||
}
|
||||
/*RValue::RVPath(path) => kvpair
|
||||
.value
|
||||
.into_context_element(renderer, breadcrumbs)
|
||||
|
||||
Reference in New Issue
Block a user