From 07873365964ab57bc8e0faa1d08c2d1377dd5600 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 11 Jan 2023 19:18:18 +0100 Subject: [PATCH] Return segment id for `BuilderArenaImplInner::allocate_segment` --- capnp/src/private/arena.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/capnp/src/private/arena.rs b/capnp/src/private/arena.rs index ddf08d9e1..18b47d2e6 100644 --- a/capnp/src/private/arena.rs +++ b/capnp/src/private/arena.rs @@ -218,7 +218,7 @@ where /// Allocates a new segment with capacity for at least `minimum_size` words. pub fn allocate_segment(&self, minimum_size: u32) { - self.inner.borrow_mut().allocate_segment(minimum_size) + self.inner.borrow_mut().allocate_segment(minimum_size); } pub fn get_segments_for_output(&self) -> OutputSegments { @@ -305,13 +305,15 @@ where A: Allocator, { /// Allocates a new segment with capacity for at least `minimum_size` words. - fn allocate_segment(&mut self, minimum_size: WordCount32) { + fn allocate_segment(&mut self, minimum_size: WordCount32) -> SegmentId { let seg = self.allocator.allocate_segment(minimum_size); + let segment_id = self.segments.len() as u32; self.segments.push(BuilderSegment { ptr: seg.0, capacity: seg.1, allocated: minimum_size, }); + segment_id } fn allocate(&mut self, segment_id: u32, amount: WordCount32) -> Option { @@ -327,10 +329,7 @@ where } // Need to allocate a new segment. - - let segment_id = self.segments.len() as u32; - self.allocate_segment(amount); - (segment_id, 0) + (self.allocate_segment(amount), 0) } fn deallocate_all(&mut self) {