Skip to content

Commit

Permalink
IndexedFields::by_id() can be const (#32430)
Browse files Browse the repository at this point in the history
make it clear that `IndexedFields::by_id()` does no allocations by making it const. this is nice when figuring out the memory footprint of readsets

GitOrigin-RevId: d83b2bfe4e3ff96962a72bd46d3dac5041d2acfa
  • Loading branch information
ldanilek authored and Convex, Inc. committed Dec 19, 2024
1 parent 135fc4b commit 714378d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use crate::{
pub struct IndexedFields(WithHeapSize<Vec<FieldPath>>);

impl IndexedFields {
pub fn by_id() -> Self {
IndexedFields(vec![].into())
pub const fn by_id() -> Self {
IndexedFields(WithHeapSize::new_vec())
}

pub fn creation_time() -> Self {
Expand Down
9 changes: 9 additions & 0 deletions crates/value/src/heap_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ impl<T: HeapSize> From<Vec<T>> for WithHeapSize<Vec<T>> {
}
}

impl<T: HeapSize> WithHeapSize<Vec<T>> {
pub const fn new_vec() -> Self {
Self {
inner: Vec::new(),
elements_heap_size: 0,
}
}
}

impl<T: HeapSize> From<WithHeapSize<Vec<T>>> for Vec<T> {
fn from(value: WithHeapSize<Vec<T>>) -> Self {
value.inner
Expand Down

0 comments on commit 714378d

Please sign in to comment.