Skip to content

Commit 1645bf0

Browse files
authored
Merge pull request #12 from Shopify/incremental-capa
Set capcity incrementally while constructing buffer
2 parents ffb9527 + c4c4bca commit 1645bf0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/stack_frames/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ static VALUE buffer_initialize(VALUE self, VALUE size) {
5858
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
5959
buffer->profile_frames = ALLOC_N(VALUE, capacity);
6060
buffer->lines = ALLOC_N(int, capacity);
61-
buffer->capacity = capacity;
6261
buffer->frames = ALLOC_N(VALUE, capacity);
6362

63+
buffer->capacity = 0;
6464
for (int i = 0; i < capacity; i++) {
6565
buffer->frames[i] = stack_frame_new(self, i);
66+
buffer->capacity++;
6667
}
6768
return Qnil;
6869
}

test/stack_frames/buffer_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def test_find
9898
assert_nil(buffer.find { |frame| false })
9999
end
100100

101+
def test_gc_stress
102+
GC.stress = true
103+
StackFrames::Buffer.new(10)
104+
ensure
105+
GC.stress = false
106+
end
107+
101108
private
102109

103110
def frame1

0 commit comments

Comments
 (0)