From 37b78f0e7f2866522a948f7db5095286489d31ee Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Thu, 28 Sep 2023 16:12:24 +0200 Subject: [PATCH] Refactor: use layout function in recordstore --- dozer-recordstore/src/in_memory/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dozer-recordstore/src/in_memory/mod.rs b/dozer-recordstore/src/in_memory/mod.rs index 80698d173e..6eb994bb6f 100644 --- a/dozer-recordstore/src/in_memory/mod.rs +++ b/dozer-recordstore/src/in_memory/mod.rs @@ -367,11 +367,8 @@ impl RecordRef { impl RecordRefInner { fn new(fields: Vec) -> Self { - let field_types = fields.iter().map(|field| field.ty()); - let field_types_layout = Layout::array::>(field_types.len()).unwrap(); - let values_size = size(field_types); - let values_layout = Layout::from_size_align(values_size, MAX_ALIGN).unwrap(); - let (layout, values_offset) = field_types_layout.extend(values_layout).unwrap(); + let n_fields = fields.len(); + let (layout, values_offset) = Self::layout(n_fields, fields.iter().map(|field| field.ty())); // SAFETY: Everything is `ALIGN` byte aligned let data = unsafe { @@ -404,7 +401,6 @@ impl RecordRefInner { // - ptr is non-null (we got it from a NonNull) // - ptr is dereferencable (its memory range is large enough and not de-allocated) // - let n_fields = fields.len(); unsafe { for field in fields { match field { @@ -445,12 +441,12 @@ impl RecordRefInner { } #[inline(always)] - fn layout<'a>( + fn layout( n_fields: usize, - field_types: impl Iterator>, + field_types: impl Iterator>, ) -> (Layout, usize) { let field_types_layout = Layout::array::>(n_fields).unwrap(); - let values_size = size(field_types.copied()); + let values_size = size(field_types); let values_layout = Layout::from_size_align(values_size, MAX_ALIGN).unwrap(); field_types_layout.extend(values_layout).unwrap() } @@ -469,7 +465,7 @@ impl Drop for RecordRefInner { unsafe { dealloc( self.data.as_ptr(), - Self::layout(self.n_fields, self.field_types().iter()).0, + Self::layout(self.n_fields, self.field_types().iter().copied()).0, ); } }