Class: StackFrames::Buffer
- Inherits:
-
Object
- Object
- StackFrames::Buffer
- Defined in:
- ext/stack_frames/buffer.c
Instance Method Summary collapse
- #[](ruby_index) ⇒ Object
- #capacity ⇒ Object
- #capture ⇒ Object
- #each ⇒ Object
- #find ⇒ Object
- #initialize(size) ⇒ Object constructor
- #length ⇒ Object
Constructor Details
#initialize(size) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'ext/stack_frames/buffer.c', line 50
static VALUE buffer_initialize(VALUE self, VALUE size) {
int capacity = NUM2INT(size);
buffer_t *buffer;
if (capacity <= 0) {
rb_raise(rb_eArgError, "non-positive buffer capacity");
}
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
buffer->profile_frames = ALLOC_N(VALUE, capacity);
buffer->lines = ALLOC_N(int, capacity);
buffer->capacity = capacity;
buffer->frames = ALLOC_N(VALUE, capacity);
for (int i = 0; i < capacity; i++) {
buffer->frames[i] = stack_frame_new(self, i);
}
return Qnil;
}
|
Instance Method Details
#[](ruby_index) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'ext/stack_frames/buffer.c', line 92
static VALUE buffer_aref(VALUE self, VALUE ruby_index) {
buffer_t *buffer;
int index = NUM2INT(ruby_index);
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
if (index >= 0 && index < buffer->length) {
return buffer->frames[index];
}
return Qnil;
}
|
#capacity ⇒ Object
85 86 87 88 89 90 |
# File 'ext/stack_frames/buffer.c', line 85
static VALUE buffer_capacity(VALUE self) {
buffer_t *buffer;
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
return INT2NUM(buffer->capacity);
}
|
#capture ⇒ Object
70 71 72 73 74 75 76 |
# File 'ext/stack_frames/buffer.c', line 70
static VALUE buffer_capture(VALUE self) {
buffer_t *buffer;
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
buffer->length = rb_profile_frames(0, buffer->capacity, buffer->profile_frames, buffer->lines);
return INT2NUM(buffer->length);
}
|
#each ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'ext/stack_frames/buffer.c', line 103
static VALUE buffer_each(VALUE self) {
buffer_t *buffer;
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
for (int i = 0; i < buffer->length; i++) {
rb_yield(buffer->frames[i]);
}
return Qnil;
}
|
#find ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'ext/stack_frames/buffer.c', line 113
static VALUE buffer_find(VALUE self) {
buffer_t *buffer;
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
for (int i = 0; i < buffer->length; i++) {
VALUE frame = buffer->frames[i];
if (RTEST(rb_yield(frame))) {
return frame;
}
}
return Qnil;
}
|
#length ⇒ Object
78 79 80 81 82 83 |
# File 'ext/stack_frames/buffer.c', line 78
static VALUE buffer_length(VALUE self) {
buffer_t *buffer;
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
return INT2NUM(buffer->length);
}
|