check if templates are ptr eq before doing full equality check

This commit is contained in:
Evan Almloff committed 2022-12-07 10:11:27 -06:00
1 parent 08da53303d
commit 84416cbe6a
2 files changed
+5 -29

No files matched your search

+3 -1
View File
@@ -61,7 +61,9 @@ impl<'b> VirtualDom {
}
fn diff_node(&mut self, left_template: &'b VNode<'b>, right_template: &'b VNode<'b>) {
if left_template.template.name != right_template.template.name {
if !std::ptr::eq(left_template.template.name, right_template.template.name)
&& left_template.template.name != right_template.template.name
{
return self.light_diff_templates(left_template, right_template);
}
+2 -28
View File
@@ -384,35 +384,9 @@ impl<'src> ScopeState {
/// Uses the currently active [`Bump`] allocator
pub fn raw_text(&'src self, args: Arguments) -> &'src str {
args.as_str().unwrap_or_else(|| {
use bumpalo::core_alloc::fmt::Write;
let mut str_buf = bumpalo::collections::String::new_in(self.bump());
struct Wrapper<'a, 'b>(&'a mut bumpalo::collections::Vec<'b, u8>);
impl<'a, 'b> std::fmt::Write for Wrapper<'a, 'b> {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
unsafe {
copy(s, self.0);
}
Ok(())
}
fn write_char(&mut self, c: char) -> std::fmt::Result {
self.0.push(c as u8);
Ok(())
}
}
unsafe fn copy<'a>(s: &str, buf: &mut bumpalo::collections::Vec<'a, u8>) {
let old_len = buf.len();
buf.reserve(s.len());
let ptr = buf.as_mut_ptr().add(old_len);
let bytes = s.as_bytes();
let str_ptr = bytes.as_ptr();
for o in 0..s.len() {
*ptr.add(o) = *str_ptr.add(o);
}
buf.set_len(old_len + s.len());
}
let _ = unsafe { std::fmt::write(&mut Wrapper(str_buf.as_mut_vec()), args) };
str_buf.write_fmt(args).unwrap();
str_buf.into_bump_str()
})
}