From 714378d1e9c081e24b085044a5f57b0e455625fd Mon Sep 17 00:00:00 2001 From: Lee Danilek Date: Thu, 19 Dec 2024 13:46:29 -0500 Subject: [PATCH] `IndexedFields::by_id()` can be const (#32430) 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 --- .../index/database_index/indexed_fields.rs | 4 ++-- crates/value/src/heap_size.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/common/src/bootstrap_model/index/database_index/indexed_fields.rs b/crates/common/src/bootstrap_model/index/database_index/indexed_fields.rs index e1e27dd4..6695f906 100644 --- a/crates/common/src/bootstrap_model/index/database_index/indexed_fields.rs +++ b/crates/common/src/bootstrap_model/index/database_index/indexed_fields.rs @@ -35,8 +35,8 @@ use crate::{ pub struct IndexedFields(WithHeapSize>); 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 { diff --git a/crates/value/src/heap_size.rs b/crates/value/src/heap_size.rs index 8d8aa68d..f6fef7ef 100644 --- a/crates/value/src/heap_size.rs +++ b/crates/value/src/heap_size.rs @@ -238,6 +238,15 @@ impl From> for WithHeapSize> { } } +impl WithHeapSize> { + pub const fn new_vec() -> Self { + Self { + inner: Vec::new(), + elements_heap_size: 0, + } + } +} + impl From>> for Vec { fn from(value: WithHeapSize>) -> Self { value.inner