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 69 |
# 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->frames = ALLOC_N(VALUE, capacity); buffer->capacity = 0; for (int i = 0; i < capacity; i++) { buffer->frames[i] = stack_frame_new(self, i); buffer->capacity++; } return Qnil; } |
Instance Method Details
#[](ruby_index) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'ext/stack_frames/buffer.c', line 93 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
86 87 88 89 90 91 |
# File 'ext/stack_frames/buffer.c', line 86 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
71 72 73 74 75 76 77 |
# File 'ext/stack_frames/buffer.c', line 71 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
104 105 106 107 108 109 110 111 112 |
# File 'ext/stack_frames/buffer.c', line 104 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
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/stack_frames/buffer.c', line 114 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
79 80 81 82 83 84 |
# File 'ext/stack_frames/buffer.c', line 79 static VALUE buffer_length(VALUE self) { buffer_t *buffer; TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer); return INT2NUM(buffer->length); } |