Another round of inlining

This commit is contained in:
novacrazy 2023-04-07 00:52:11 -05:00
parent d3b3ce6980
commit ba9d3c1602
6 changed files with 26 additions and 4 deletions

View file

@ -139,13 +139,15 @@ where
/// Creates a new dynamic child which will re-render whenever it's /// Creates a new dynamic child which will re-render whenever it's
/// signal dependencies change. /// signal dependencies change.
#[track_caller] #[track_caller]
#[inline(always)]
pub fn new(child_fn: CF) -> Self { pub fn new(child_fn: CF) -> Self {
Self::new_with_id(HydrationCtx::id(), child_fn) Self::new_with_id(HydrationCtx::id(), child_fn)
} }
#[doc(hidden)] #[doc(hidden)]
#[track_caller] #[track_caller]
pub fn new_with_id(id: HydrationKey, child_fn: CF) -> Self { #[inline(always)]
pub const fn new_with_id(id: HydrationKey, child_fn: CF) -> Self {
Self { id, child_fn } Self { id, child_fn }
} }
} }

View file

@ -257,6 +257,7 @@ impl Mountable for EachItem {
} }
} }
#[inline(always)]
fn get_opening_node(&self) -> web_sys::Node { fn get_opening_node(&self) -> web_sys::Node {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
return self.opening.node.clone(); return self.opening.node.clone();
@ -328,7 +329,8 @@ where
T: 'static, T: 'static,
{ {
/// Creates a new [`Each`] component. /// Creates a new [`Each`] component.
pub fn new(items_fn: IF, key_fn: KF, each_fn: EF) -> Self { #[inline(always)]
pub const fn new(items_fn: IF, key_fn: KF, each_fn: EF) -> Self {
Self { Self {
items_fn, items_fn,
each_fn, each_fn,

View file

@ -5,16 +5,18 @@ use std::{collections::HashMap, error::Error, sync::Arc};
/// A struct to hold all the possible errors that could be provided by child Views /// A struct to hold all the possible errors that could be provided by child Views
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
#[repr(transparent)]
pub struct Errors(HashMap<ErrorKey, Arc<dyn Error + Send + Sync>>); pub struct Errors(HashMap<ErrorKey, Arc<dyn Error + Send + Sync>>);
/// A unique key for an error that occurs at a particular location in the user interface. /// A unique key for an error that occurs at a particular location in the user interface.
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct ErrorKey(String); #[repr(transparent)]
impl<T> From<T> for ErrorKey impl<T> From<T> for ErrorKey
where where
T: Into<String>, T: Into<String>,
{ {
#[inline(always)]
fn from(key: T) -> ErrorKey { fn from(key: T) -> ErrorKey {
ErrorKey(key.into()) ErrorKey(key.into())
} }
@ -24,12 +26,14 @@ impl IntoIterator for Errors {
type Item = (ErrorKey, Arc<dyn Error + Send + Sync>); type Item = (ErrorKey, Arc<dyn Error + Send + Sync>);
type IntoIter = IntoIter; type IntoIter = IntoIter;
#[inline(always)]
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
IntoIter(self.0.into_iter()) IntoIter(self.0.into_iter())
} }
} }
/// An owning iterator over all the errors contained in the [Errors] struct. /// An owning iterator over all the errors contained in the [Errors] struct.
#[repr(transparent)]
pub struct IntoIter( pub struct IntoIter(
std::collections::hash_map::IntoIter< std::collections::hash_map::IntoIter<
ErrorKey, ErrorKey,
@ -40,6 +44,7 @@ pub struct IntoIter(
impl Iterator for IntoIter { impl Iterator for IntoIter {
type Item = (ErrorKey, Arc<dyn Error + Send + Sync>); type Item = (ErrorKey, Arc<dyn Error + Send + Sync>);
#[inline(always)]
fn next( fn next(
&mut self, &mut self,
) -> std::option::Option<<Self as std::iter::Iterator>::Item> { ) -> std::option::Option<<Self as std::iter::Iterator>::Item> {
@ -48,6 +53,7 @@ impl Iterator for IntoIter {
} }
/// An iterator over all the errors contained in the [Errors] struct. /// An iterator over all the errors contained in the [Errors] struct.
#[repr(transparent)]
pub struct Iter<'a>( pub struct Iter<'a>(
std::collections::hash_map::Iter< std::collections::hash_map::Iter<
'a, 'a,
@ -59,6 +65,7 @@ pub struct Iter<'a>(
impl<'a> Iterator for Iter<'a> { impl<'a> Iterator for Iter<'a> {
type Item = (&'a ErrorKey, &'a Arc<dyn Error + Send + Sync>); type Item = (&'a ErrorKey, &'a Arc<dyn Error + Send + Sync>);
#[inline(always)]
fn next( fn next(
&mut self, &mut self,
) -> std::option::Option<<Self as std::iter::Iterator>::Item> { ) -> std::option::Option<<Self as std::iter::Iterator>::Item> {
@ -127,6 +134,7 @@ where
} }
impl Errors { impl Errors {
/// Returns `true` if there are no errors. /// Returns `true` if there are no errors.
#[inline(always)]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.0.is_empty() self.0.is_empty()
} }
@ -156,6 +164,7 @@ impl Errors {
} }
/// An iterator over all the errors, in arbitrary order. /// An iterator over all the errors, in arbitrary order.
#[inline(always)]
pub fn iter(&self) -> Iter<'_> { pub fn iter(&self) -> Iter<'_> {
Iter(self.0.iter()) Iter(self.0.iter())
} }

View file

@ -43,17 +43,20 @@ impl From<View> for Fragment {
impl Fragment { impl Fragment {
/// Creates a new [`Fragment`] from a [`Vec<Node>`]. /// Creates a new [`Fragment`] from a [`Vec<Node>`].
#[inline(always)]
pub fn new(nodes: Vec<View>) -> Self { pub fn new(nodes: Vec<View>) -> Self {
Self::new_with_id(HydrationCtx::id(), nodes) Self::new_with_id(HydrationCtx::id(), nodes)
} }
/// Creates a new [`Fragment`] from a function that returns [`Vec<Node>`]. /// Creates a new [`Fragment`] from a function that returns [`Vec<Node>`].
#[inline(always)]
pub fn lazy(nodes: impl FnOnce() -> Vec<View>) -> Self { pub fn lazy(nodes: impl FnOnce() -> Vec<View>) -> Self {
Self::new_with_id(HydrationCtx::id(), nodes()) Self::new_with_id(HydrationCtx::id(), nodes())
} }
/// Creates a new [`Fragment`] with the given hydration ID from a [`Vec<Node>`]. /// Creates a new [`Fragment`] with the given hydration ID from a [`Vec<Node>`].
pub fn new_with_id(id: HydrationKey, nodes: Vec<View>) -> Self { #[inline(always)]
pub const fn new_with_id(id: HydrationKey, nodes: Vec<View>) -> Self {
Self { Self {
id, id,
nodes, nodes,
@ -63,11 +66,13 @@ impl Fragment {
} }
/// Gives access to the [View] children contained within the fragment. /// Gives access to the [View] children contained within the fragment.
#[inline(always)]
pub fn as_children(&self) -> &[View] { pub fn as_children(&self) -> &[View] {
&self.nodes &self.nodes
} }
/// Returns the fragment's hydration ID. /// Returns the fragment's hydration ID.
#[inline(always)]
pub fn id(&self) -> &HydrationKey { pub fn id(&self) -> &HydrationKey {
&self.id &self.id
} }

View file

@ -40,14 +40,17 @@ impl Default for UnitRepr {
#[cfg(all(target_arch = "wasm32", feature = "web"))] #[cfg(all(target_arch = "wasm32", feature = "web"))]
impl Mountable for UnitRepr { impl Mountable for UnitRepr {
#[inline(always)]
fn get_mountable_node(&self) -> web_sys::Node { fn get_mountable_node(&self) -> web_sys::Node {
self.comment.node.clone().unchecked_into() self.comment.node.clone().unchecked_into()
} }
#[inline(always)]
fn get_opening_node(&self) -> web_sys::Node { fn get_opening_node(&self) -> web_sys::Node {
self.comment.node.clone().unchecked_into() self.comment.node.clone().unchecked_into()
} }
#[inline(always)]
fn get_closing_node(&self) -> web_sys::Node { fn get_closing_node(&self) -> web_sys::Node {
self.comment.node.clone().unchecked_into() self.comment.node.clone().unchecked_into()
} }

View file

@ -135,6 +135,7 @@ macro_rules! impl_into_attr_boxed {
} }
impl IntoAttribute for Option<Attribute> { impl IntoAttribute for Option<Attribute> {
#[inline(always)]
fn into_attribute(self, cx: Scope) -> Attribute { fn into_attribute(self, cx: Scope) -> Attribute {
self.unwrap_or(Attribute::Option(cx, None)) self.unwrap_or(Attribute::Option(cx, None))
} }