Skip to content

Commit a09abbb

Browse files
committed
Remove unnecessary NULL check when calling blocks
This makes calling blocks zero-cost.
1 parent ac4fadc commit a09abbb

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

crates/block2/src/block.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ impl<F: ?Sized> Block<F> {
9696
unsafe { RcBlock::copy(ptr) }.unwrap_or_else(|| block_copy_fail())
9797
}
9898

99+
#[inline]
99100
pub(crate) fn invoke_ptr(&self) -> unsafe extern "C-unwind" fn() {
100-
// TODO: Is `invoke` actually ever null?
101-
self.header().invoke.unwrap_or_else(|| unreachable!())
101+
// SAFETY: `invoke` is never NULL - Clang also assumes this in its
102+
// codegen, and will null ptr deref if it is.
103+
unsafe { self.header().invoke.unwrap_unchecked() }
102104
}
103105
}
104106

0 commit comments

Comments
 (0)