MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / next

Method next

crates/table/src/table.rs:2095–2133  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

2093 type Item = RowRef<'a>;
2094
2095 fn next(&mut self) -> Option<Self::Item> {
2096 // This could have been written using `.flat_map`,
2097 // but we don't have `type Foo = impl Iterator<...>;` on stable yet.
2098 loop {
2099 match &mut self.current_page {
2100 // We're currently visiting a page,
2101 Some(iter_fixed_len) => {
2102 if let Some(page_offset) = iter_fixed_len.next() {
2103 // There's still at least one row in that page to visit,
2104 // return a ref to that row.
2105 let ptr =
2106 RowPointer::new(false, self.current_page_idx, page_offset, self.table.squashed_offset);
2107
2108 // SAFETY: `offset` came from the `iter_fixed_len`, so it must point to a valid row.
2109 let row_ref = unsafe { self.table.get_row_ref_unchecked(self.blob_store, ptr) };
2110 return Some(row_ref);
2111 } else {
2112 // We've finished visiting that page, so set `current_page` to `None`,
2113 // increment `self.current_page_idx` to the index of the next page,
2114 // and go to the `None` case (1) in the match.
2115 self.current_page = None;
2116 self.current_page_idx.0 += 1;
2117 }
2118 }
2119
2120 // (1) If we aren't currently visiting a page,
2121 // the `else` case in the `Some` match arm
2122 // already incremented `self.current_page_idx`,
2123 // or we're just beginning and so it was initialized as 0.
2124 None => {
2125 // If there's another page, set `self.current_page` to it,
2126 // and go to the `Some` case in the match.
2127 let next_page = self.table.pages().get(self.current_page_idx.idx())?;
2128 let iter = next_page.iter_fixed_len(self.table.row_size());
2129 self.current_page = Some(iter);
2130 }
2131 }
2132 }
2133 }
2134}
2135
2136/// A combined table and index,

Callers 3

blob_store_bytesMethod · 0.45

Calls 8

get_row_ref_uncheckedMethod · 0.80
pagesMethod · 0.80
iter_fixed_lenMethod · 0.80
row_sizeMethod · 0.80
newFunction · 0.50
getMethod · 0.45
idxMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected