Skip to content

Commit

Permalink
Return segment id for BuilderArenaImplInner::allocate_segment
Browse files Browse the repository at this point in the history
  • Loading branch information
marmeladema committed Jan 11, 2023
1 parent 65a59c7 commit 0787336
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions capnp/src/private/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<u32> {
Expand All @@ -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) {
Expand Down

0 comments on commit 0787336

Please sign in to comment.