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

Method clone_structure

crates/table/src/table.rs:1595–1615  ·  view source on GitHub ↗

Clones the structure of this table into a new one with the same schema, visitor program, and indices. The new table will be completely empty and will use the given `squashed_offset` instead of that of `self`.

(&self, squashed_offset: SquashedOffset)

Source from the content-addressed store, hash-verified

1593 /// The new table will be completely empty
1594 /// and will use the given `squashed_offset` instead of that of `self`.
1595 pub fn clone_structure(&self, squashed_offset: SquashedOffset) -> Self {
1596 // Clone a bunch of static data.
1597 // NOTE(centril): It's important that these be cheap to clone.
1598 // This is why they are all `Arc`ed or have some sort of small-vec optimization.
1599 let schema = self.schema.clone();
1600 let layout = self.row_layout().clone();
1601 let sbl = self.inner.static_layout.clone();
1602 let visitor = self.inner.visitor_prog.clone();
1603
1604 // If we had a pointer map, we'll have one in the cloned one as well, but empty.
1605 let pm = self.pointer_map.as_ref().map(|_| PointerMap::default());
1606
1607 // Make the new table.
1608 let mut new = Table::new_raw(schema, layout, sbl, visitor, squashed_offset, pm);
1609
1610 // Clone the index structure. The table is empty, so no need to `build_from_rows`.
1611 for (&index_id, index) in self.indexes.iter() {
1612 new.indexes.insert(index_id, index.clone_structure());
1613 }
1614 new
1615 }
1616
1617 /// Returns the number of bytes occupied by the pages and the blob store.
1618 /// Note that result can be more than the actual physical size occupied by the table

Callers 3

create_table_internalMethod · 0.45
create_indexMethod · 0.45

Calls 6

row_layoutMethod · 0.80
iterMethod · 0.65
insertMethod · 0.65
cloneMethod · 0.45
mapMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected