diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 59931307..fd08a535 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -161,6 +161,7 @@ pub trait Template: fmt::Display + FastWritable { } impl fmt::Write for Wrapped { + #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { if let Err(err) = self.writer.write_all(s.as_bytes()) { self.err = Some(err); @@ -286,6 +287,7 @@ impl DynTemplate for T { ::render(self) } + #[inline] #[cfg(feature = "alloc")] fn dyn_render_with_values(&self, values: &dyn Values) -> Result { ::render_with_values(self, values) @@ -296,6 +298,7 @@ impl DynTemplate for T { ::render_into(self, writer) } + #[inline] fn dyn_render_into_with_values( &self, writer: &mut dyn fmt::Write, @@ -304,6 +307,7 @@ impl DynTemplate for T { ::render_into_with_values(self, writer, values) } + #[inline] #[cfg(feature = "std")] fn dyn_write_into(&self, writer: &mut dyn io::Write) -> io::Result<()> { ::write_into(self, writer) @@ -513,6 +517,7 @@ const _: () = { } impl FastWritable for fmt::Arguments<'_> { + #[inline] fn write_into( &self, dest: &mut W, diff --git a/askama/src/values.rs b/askama/src/values.rs index 937a8849..3c8b4850 100644 --- a/askama/src/values.rs +++ b/askama/src/values.rs @@ -7,11 +7,15 @@ use crate::Error; pub const NO_VALUES: &dyn Values = &(); /// Try to find `key` in `values` and then to convert it to `T`. +#[inline] pub fn get_value(values: &dyn Values, key: impl AsRef) -> Result<&T, Error> { - let Some(src) = values.get_value(key.as_ref()) else { - return Err(Error::ValueMissing); - }; + values + .get_value(key.as_ref()) + .ok_or(Error::ValueMissing) + .and_then(convert_value) +} +fn convert_value(src: &dyn Any) -> Result<&T, Error> { if let Some(value) = src.downcast_ref::() { return Ok(value); } else if let Some(value) = src.downcast_ref::<&T>() { @@ -90,6 +94,7 @@ where K: Borrow, V: Value, { + #[inline] fn get_value<'a>(&'a self, key: &str) -> Option<&'a dyn Any> { find_value_linear(self.iter(), key) }