pub enum PageHandle {
Shared(Arc<Page>),
Owned(Page),
}Expand description
Owning handle to a page returned by ReaderSnapshot::read_page.
#81: read_page used to return an owned Page (a 4 KiB body
clone) on every call, including the common frozen-view hit. A
point read descends catalog + primary and an index lookup descends
two trees, so each op paid 3-5 such 4 KiB copies. PageHandle
removes the copy on the hot path:
PageHandle::Shared— frozen-view hit. Holds anArc<Page>cloned from the snapshot’s view (a refcount bump, no body copy). Sound because committed pages are immutable: a new version is a freshArcunder the samePageId, never an in-place mutation of a sharedArc(seefrozen_view).PageHandle::Owned— disk / cache miss. Holds the freshly read, checksum-verifiedPageproduced by the existingread_main_file_page/read_cache_or_main(read_through) path; integrity behaviour is unchanged.
Concrete enum, not dyn (Rule 9). Both arms are a single pointer
(Arc<Page> and Page’s Box<[u8; PAGE_SIZE]>), so the variants
are balanced and clippy::large_enum_variant does not fire.
Variants§
Frozen-view hit — shares the snapshot’s Arc<Page> with no
4 KiB body clone.
Owned(Page)
Disk / cache miss — owns the checksum-verified page bytes.
Implementations§
Source§impl PageHandle
impl PageHandle
Sourcepub fn as_bytes(&self) -> &[u8; 4096]
pub fn as_bytes(&self) -> &[u8; 4096]
Borrow the page’s raw bytes for decoding, without copying.
The match over both arms is total — no Result, no
unwrap/expect (Rule 7): every PageHandle always holds a
readable page in exactly one of its two arms. Callers that only
need to decode (e.g. BTree::get_via_snapshot,
Catalog::lookup_via_snapshot) should keep the PageHandle
alive for the duration of the borrow and call this.
Sourcepub fn into_page(self) -> Page
pub fn into_page(self) -> Page
Consume the handle and produce an owned Page.
The Shared arm clones the body exactly once (only when an
owned page is genuinely required, e.g. the public
crate::ReadTxn::read_page whose pager lock guard cannot
outlive the call); the Owned arm moves with no copy. This is
the only place the hot-path frozen-view clone is paid, and
only for callers that ask for ownership.
Trait Implementations§
Source§impl Clone for PageHandle
impl Clone for PageHandle
Source§fn clone(&self) -> PageHandle
fn clone(&self) -> PageHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more