From: Joshua Simmons Date: Fri, 11 Nov 2022 20:20:14 +0000 (+0100) Subject: Remove comparison with the empty page X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=b8531bc995e5ff870b0879bb0ee6835e1bd64470;p=josh%2Fnarcissus Remove comparison with the empty page By marking the empty page as a "stack" page, we can avoid needing to compare with the empty page when allocating from a hybrid array. --- diff --git a/narcissus-core/src/arena.rs b/narcissus-core/src/arena.rs index 18e882e..4853495 100644 --- a/narcissus-core/src/arena.rs +++ b/narcissus-core/src/arena.rs @@ -33,7 +33,9 @@ struct PagePointer(*mut PageFooter); impl PagePointer { #[inline(always)] fn empty() -> PagePointer { - PagePointer(&EMPTY_PAGE as *const PageFooterSync as *mut PageFooter) + // We pretend the empty page is a "stack" pointer, as it allows us to remove a branch from + // the hybrid array setup. + PagePointer::new_stack(&EMPTY_PAGE as *const PageFooterSync as *mut PageFooter) } #[inline(always)] @@ -48,7 +50,7 @@ impl PagePointer { #[inline(always)] fn is_empty(self) -> bool { - self.0 == &EMPTY_PAGE as *const PageFooterSync as *mut PageFooter + self.as_ptr() == &EMPTY_PAGE as *const PageFooterSync as *mut PageFooter } #[inline(always)] @@ -579,7 +581,9 @@ impl HybridArena { // It's safe to reset the page in this case, becuase it's only possible to move the arena // while there are no references pinning it in place. let page = self.page_list_head.get(); - if page.is_empty() || (page.is_stack() && page.as_ptr() != self.footer.as_ptr()) { + // We initially point to the empty page, but mark it as a stack page so this branch is + // sufficient to handle both empty and moved cases. + if page.is_stack() && page.as_ptr() != self.footer.as_ptr() { unsafe { self.setup_hybrid_page() } }