Create from_borrowed and from_owned constructors for IceResult and BreadcrumbTreeElement.
In an effort to keep track of how often memory is getting heap allocated, I am implementing constructors for IceResult and BreadcrumbTreeElement. This should limit the places that I call Rc::new and allow me to place tracing code into it later to ensure all code paths doing heap allocation make sense.
This commit is contained in:
@@ -116,7 +116,7 @@ impl<C: ContextElement> IntoContextElement for C {
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&'a BreadcrumbTree<'a>>,
|
||||
) -> Option<IceResult<'a>> {
|
||||
Some(IceResult::Borrowed(self))
|
||||
Some(IceResult::from_borrowed(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,14 @@ pub enum IceResult<'a> {
|
||||
}
|
||||
|
||||
impl<'a> IceResult<'a> {
|
||||
pub fn from_owned<C: 'static + ContextElement>(val: C) -> IceResult<'a> {
|
||||
IceResult::Owned(Rc::new(val))
|
||||
}
|
||||
|
||||
pub fn from_borrowed(val: &'a dyn ContextElement) -> IceResult<'a> {
|
||||
IceResult::Borrowed(val)
|
||||
}
|
||||
|
||||
pub fn get_context_element_reference(&self) -> &dyn ContextElement {
|
||||
match self {
|
||||
IceResult::Owned(rc_ce) => rc_ce.as_ref(),
|
||||
@@ -155,10 +163,9 @@ impl<'a> IntoContextElement for IceResult<'a> {
|
||||
renderer: &DustRenderer,
|
||||
breadcrumbs: Option<&'b BreadcrumbTree<'b>>,
|
||||
) -> Option<IceResult<'b>> {
|
||||
// Some(*self)
|
||||
match self {
|
||||
IceResult::Owned(rc_ce) => Some(IceResult::Borrowed(rc_ce.as_ref())),
|
||||
IceResult::Borrowed(ce) => Some(IceResult::Borrowed(*ce)),
|
||||
IceResult::Owned(rc_ce) => Some(IceResult::from_borrowed(rc_ce.as_ref())),
|
||||
IceResult::Borrowed(ce) => Some(IceResult::from_borrowed(*ce)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user