ferret 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/ext/Makefile +2 -2
  2. data/ext/ferret.c +27 -2
  3. data/ext/ferret.h +59 -16
  4. data/ext/ferret_ext.so +0 -0
  5. data/ext/index_io.c +72 -77
  6. data/ext/priority_queue.c +150 -145
  7. data/ext/ram_directory.c +47 -42
  8. data/ext/segment_merge_queue.c +4 -8
  9. data/ext/segment_term_enum.c +324 -0
  10. data/ext/similarity.c +59 -0
  11. data/ext/string_helper.c +2 -2
  12. data/ext/tags +150 -46
  13. data/ext/term.c +107 -152
  14. data/ext/term_buffer.c +105 -174
  15. data/ext/term_infos_reader.c +54 -0
  16. data/ext/terminfo.c +160 -0
  17. data/ext/token.c +93 -0
  18. data/lib/ferret.rb +1 -1
  19. data/lib/ferret/analysis/analyzers.rb +18 -0
  20. data/lib/ferret/analysis/standard_tokenizer.rb +19 -14
  21. data/lib/ferret/analysis/token.rb +8 -1
  22. data/lib/ferret/analysis/tokenizers.rb +10 -5
  23. data/lib/ferret/document/field.rb +33 -11
  24. data/lib/ferret/index/document_writer.rb +3 -2
  25. data/lib/ferret/index/field_infos.rb +38 -12
  26. data/lib/ferret/index/fields_io.rb +10 -4
  27. data/lib/ferret/index/index.rb +20 -4
  28. data/lib/ferret/index/index_reader.rb +19 -4
  29. data/lib/ferret/index/index_writer.rb +1 -1
  30. data/lib/ferret/index/multi_reader.rb +21 -7
  31. data/lib/ferret/index/segment_merge_info.rb +24 -22
  32. data/lib/ferret/index/segment_merge_queue.rb +2 -2
  33. data/lib/ferret/index/segment_merger.rb +28 -11
  34. data/lib/ferret/index/segment_reader.rb +19 -4
  35. data/lib/ferret/index/segment_term_enum.rb +3 -11
  36. data/lib/ferret/index/term_buffer.rb +13 -16
  37. data/lib/ferret/index/term_doc_enum.rb +8 -5
  38. data/lib/ferret/index/term_enum.rb +2 -2
  39. data/lib/ferret/index/term_info.rb +1 -5
  40. data/lib/ferret/index/term_infos_io.rb +2 -0
  41. data/lib/ferret/query_parser/query_parser.tab.rb +7 -7
  42. data/lib/ferret/search/phrase_scorer.rb +0 -1
  43. data/lib/ferret/search/similarity.rb +2 -2
  44. data/lib/ferret/search/term_scorer.rb +2 -2
  45. data/lib/ferret/store/directory.rb +2 -0
  46. data/lib/ferret/store/fs_store.rb +16 -3
  47. data/lib/ferret/store/ram_store.rb +2 -2
  48. data/test/unit/document/tc_field.rb +9 -0
  49. data/test/unit/index/tc_field_infos.rb +29 -21
  50. data/test/unit/index/tc_index.rb +44 -7
  51. data/test/unit/index/tc_term_buffer.rb +3 -3
  52. data/test/unit/index/tc_term_info.rb +1 -1
  53. data/test/unit/query_parser/tc_query_parser.rb +1 -1
  54. data/test/unit/search/tc_index_searcher.rb +3 -0
  55. data/test/unit/store/tc_fs_store.rb +47 -16
  56. data/test/unit/store/tc_ram_store.rb +1 -1
  57. metadata +8 -3
data/ext/priority_queue.c CHANGED
@@ -16,188 +16,193 @@ frt_priq_free(void *p)
16
16
  static VALUE
17
17
  frt_priq_alloc(VALUE klass)
18
18
  {
19
- PriorityQueue *priq;
20
- priq = (PriorityQueue *)ALLOC(PriorityQueue);
21
- priq->len = 0;
22
- priq->size = 0;
23
- VALUE rpriq = Data_Wrap_Struct(klass, NULL, frt_priq_free, priq);
24
- return rpriq;
19
+ PriorityQueue *priq;
20
+ VALUE rpriq;
21
+ priq = (PriorityQueue *)ALLOC(PriorityQueue);
22
+ priq->len = 0;
23
+ priq->size = 0;
24
+ rpriq = Data_Wrap_Struct(klass, NULL, frt_priq_free, priq);
25
+ return rpriq;
25
26
  }
26
27
 
27
28
  static VALUE
28
29
  frt_priq_init(VALUE self, VALUE rsize)
29
30
  {
30
- VALUE heap;
31
- PriorityQueue *priq;
32
-
33
- int size = FIX2INT(rsize);
34
- heap = rb_ary_new2(size+1);
35
- Data_Get_Struct(self, PriorityQueue, priq);
36
-
37
- priq->heap = RARRAY(heap)->ptr;
38
- priq->size = size;
39
- rb_iv_set(self, "@heap", heap);
40
- return self;
31
+ VALUE heap;
32
+ PriorityQueue *priq;
33
+
34
+ int size = FIX2INT(rsize);
35
+ heap = rb_ary_new2(size+1);
36
+ Data_Get_Struct(self, PriorityQueue, priq);
37
+
38
+ priq->heap = RARRAY(heap)->ptr;
39
+ priq->size = size;
40
+ rb_iv_set(self, "@heap", heap);
41
+ return self;
41
42
  }
42
43
 
43
44
  void
44
45
  priq_up(PriorityQueue *priq, VALUE self, VALUE rary)
45
46
  {
46
- int i,j;
47
- VALUE *heap, node;
48
-
49
- i = priq->len;
50
- heap = priq->heap;
51
- node = heap[i];
52
- j = i >> 1;
53
- while((j > 0) && rb_funcall(self, less_than, 2, node, heap[j])){
54
- heap[i] = heap[j];
55
- i = j;
56
- j = j >> 1;
57
- }
58
- rb_ary_store(rary, i, node);
47
+ int i,j;
48
+ VALUE *heap, node;
49
+
50
+ i = priq->len;
51
+ heap = priq->heap;
52
+ node = heap[i];
53
+ j = i >> 1;
54
+ while((j > 0) && rb_funcall(self, less_than, 2, node, heap[j])){
55
+ heap[i] = heap[j];
56
+ i = j;
57
+ j = j >> 1;
58
+ }
59
+ rb_ary_store(rary, i, node);
59
60
  }
60
61
 
61
62
  void
62
63
  priq_down(PriorityQueue *priq, VALUE self, VALUE rary)
63
64
  {
64
- int i, j, k, len;
65
- VALUE *heap, node;
66
-
67
- i = 1;
68
- heap = priq->heap;
69
- len = priq->len;
70
- node = heap[i];
71
- j = i << 1;
72
- k = j + 1;
73
-
74
- if ((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
75
- j = k;
76
-
77
- while((j <= len) && rb_funcall(self, less_than, 2, heap[j], node)){
78
- heap[i] = heap[j];
79
- i = j;
80
- j = i << 1;
81
- k = j + 1;
82
- if((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
83
- j = k;
84
- }
85
- rb_ary_store(rary,i, node);
65
+ int i, j, k, len;
66
+ VALUE *heap, node;
67
+
68
+ i = 1;
69
+ heap = priq->heap;
70
+ len = priq->len;
71
+ node = heap[i];
72
+ j = i << 1;
73
+ k = j + 1;
74
+
75
+ if ((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
76
+ j = k;
77
+
78
+ while((j <= len) && rb_funcall(self, less_than, 2, heap[j], node)){
79
+ heap[i] = heap[j];
80
+ i = j;
81
+ j = i << 1;
82
+ k = j + 1;
83
+ if((k <= len) && rb_funcall(self, less_than, 2, heap[k], heap[j]))
84
+ j = k;
85
+ }
86
+ rb_ary_store(rary,i, node);
86
87
  }
87
88
 
88
89
  static VALUE
89
90
  frt_priq_push(VALUE self, VALUE e)
90
91
  {
91
- PriorityQueue *priq;
92
- Data_Get_Struct(self, PriorityQueue, priq);
93
- int len = priq->len;
94
- VALUE rary = rb_iv_get(self, "@heap");
95
-
96
- len++;
97
- rb_ary_store(rary, len, e);
98
- priq->len = len;
99
- priq_up(priq, self, rary);
100
-
101
- return Qnil;
92
+ PriorityQueue *priq;
93
+ int len;
94
+ VALUE rary;
95
+ Data_Get_Struct(self, PriorityQueue, priq);
96
+ len = priq->len;
97
+ rary = rb_iv_get(self, "@heap");
98
+
99
+ len++;
100
+ rb_ary_store(rary, len, e);
101
+ priq->len = len;
102
+ priq_up(priq, self, rary);
103
+
104
+ return Qnil;
102
105
  }
103
106
 
104
107
  static VALUE
105
108
  frt_priq_insert(VALUE self, VALUE e)
106
109
  {
107
- PriorityQueue *priq;
108
- VALUE *heap, rary;
109
- int len, size;
110
- rary = rb_iv_get(self, "@heap");
111
-
112
- Data_Get_Struct(self, PriorityQueue, priq);
113
- len = priq->len;
114
- size = priq->size;
115
- heap = priq->heap;
116
-
117
- if(len < size){
118
- frt_priq_push(self, e);
119
- return 1;
120
- } else if ((len > 0) && !rb_funcall(self, less_than, 2, e, heap[1])) {
121
- heap[1] = e;
122
- priq_down(priq, self, rary);
123
- return 1;
124
- } else {
125
- return 0;
110
+ PriorityQueue *priq;
111
+ VALUE *heap, rary;
112
+ int len, size;
113
+ rary = rb_iv_get(self, "@heap");
114
+
115
+ Data_Get_Struct(self, PriorityQueue, priq);
116
+ len = priq->len;
117
+ size = priq->size;
118
+ heap = priq->heap;
119
+
120
+ if(len < size){
121
+ frt_priq_push(self, e);
122
+ return 1;
123
+ } else if ((len > 0) && !rb_funcall(self, less_than, 2, e, heap[1])) {
124
+ heap[1] = e;
125
+ priq_down(priq, self, rary);
126
+ return 1;
127
+ } else {
128
+ return 0;
126
129
  }
127
130
  }
128
131
 
129
132
  static VALUE
130
133
  frt_priq_top(VALUE self)
131
134
  {
132
- PriorityQueue *priq;
133
- VALUE *heap;
134
- int len;
135
-
136
- Data_Get_Struct(self, PriorityQueue, priq);
137
- len = priq->len;
138
- heap = priq->heap;
139
-
140
- if(len > 0)
141
- return heap[1];
142
- else
143
- return Qnil;
135
+ PriorityQueue *priq;
136
+ VALUE *heap;
137
+ int len;
138
+
139
+ Data_Get_Struct(self, PriorityQueue, priq);
140
+ len = priq->len;
141
+ heap = priq->heap;
142
+
143
+ if(len > 0)
144
+ return heap[1];
145
+ else
146
+ return Qnil;
144
147
  }
145
148
 
146
149
  static VALUE
147
150
  frt_priq_pop(VALUE self)
148
151
  {
149
- PriorityQueue *priq;
150
- VALUE *heap, rary;
151
- int len;
152
-
153
- Data_Get_Struct(self, PriorityQueue, priq);
154
- rary = rb_iv_get(self, "@heap");
155
- len = priq->len;
156
- heap = priq->heap;
157
-
158
- if(len > 0){
159
- VALUE res = heap[1];
160
- heap[1] = heap[len];
161
- heap[len] = Qnil;
162
- len--;
163
- priq->len = len;
164
- priq_down(priq, self, rary);
165
- return res;
166
- } else
167
- return Qnil;
152
+ PriorityQueue *priq;
153
+ VALUE *heap, rary;
154
+ int len;
155
+
156
+ Data_Get_Struct(self, PriorityQueue, priq);
157
+ rary = rb_iv_get(self, "@heap");
158
+ len = priq->len;
159
+ heap = priq->heap;
160
+
161
+ if(len > 0){
162
+ VALUE res = heap[1];
163
+ heap[1] = heap[len];
164
+ heap[len] = Qnil;
165
+ len--;
166
+ priq->len = len;
167
+ priq_down(priq, self, rary);
168
+ return res;
169
+ } else
170
+ return Qnil;
168
171
  }
169
172
 
170
173
  static VALUE
171
174
  frt_priq_clear(VALUE self)
172
175
  {
173
- PriorityQueue *priq;
174
- Data_Get_Struct(self, PriorityQueue, priq);
175
- VALUE heap = rb_ary_new2(priq->size+1);
176
- rb_iv_set(self, "@heap", heap);
177
- priq->heap = RARRAY(heap)->ptr;
178
- priq->len = 0;
179
- return Qnil;
180
-
176
+ PriorityQueue *priq;
177
+ VALUE heap;
178
+ Data_Get_Struct(self, PriorityQueue, priq);
179
+ heap = rb_ary_new2(priq->size+1);
180
+ rb_iv_set(self, "@heap", heap);
181
+ priq->heap = RARRAY(heap)->ptr;
182
+ priq->len = 0;
183
+ return Qnil;
184
+
181
185
  }
182
186
 
183
187
  static VALUE
184
188
  frt_priq_size(VALUE self)
185
189
  {
186
- PriorityQueue *priq;
187
- Data_Get_Struct(self, PriorityQueue, priq);
188
- return INT2FIX(priq->len);
190
+ PriorityQueue *priq;
191
+ Data_Get_Struct(self, PriorityQueue, priq);
192
+ return INT2FIX(priq->len);
189
193
  }
190
194
 
191
195
  static VALUE
192
196
  frt_priq_adjust_top(VALUE self)
193
197
  {
194
- PriorityQueue *priq;
195
- Data_Get_Struct(self, PriorityQueue, priq);
196
- VALUE rary = rb_iv_get(self, "@heap");
197
-
198
- priq_down(priq, self, rary);
199
-
200
- return Qnil;
198
+ PriorityQueue *priq;
199
+ VALUE rary;
200
+ Data_Get_Struct(self, PriorityQueue, priq);
201
+ rary = rb_iv_get(self, "@heap");
202
+
203
+ priq_down(priq, self, rary);
204
+
205
+ return Qnil;
201
206
  }
202
207
 
203
208
 
@@ -210,18 +215,18 @@ frt_priq_adjust_top(VALUE self)
210
215
  void
211
216
  Init_priority_queue(void)
212
217
  {
213
- less_than = rb_intern("less_than");
214
- put_heap = rb_intern("put_heap");
215
-
216
- cPriorityQueue = rb_define_class_under(mUtils, "PriorityQueue", rb_cObject);
217
- rb_define_alloc_func(cPriorityQueue, frt_priq_alloc);
218
-
219
- rb_define_method(cPriorityQueue, "initialize", frt_priq_init, 1);
220
- rb_define_method(cPriorityQueue, "pop", frt_priq_pop, 0);
221
- rb_define_method(cPriorityQueue, "top", frt_priq_top, 0);
222
- rb_define_method(cPriorityQueue, "clear", frt_priq_clear, 0);
223
- rb_define_method(cPriorityQueue, "insert", frt_priq_insert, 1);
224
- rb_define_method(cPriorityQueue, "push", frt_priq_push, 1);
225
- rb_define_method(cPriorityQueue, "size", frt_priq_size, 0);
226
- rb_define_method(cPriorityQueue, "adjust_top", frt_priq_adjust_top, 0);
218
+ less_than = rb_intern("less_than");
219
+ put_heap = rb_intern("put_heap");
220
+
221
+ cPriorityQueue = rb_define_class_under(mUtils, "PriorityQueue", rb_cObject);
222
+ rb_define_alloc_func(cPriorityQueue, frt_priq_alloc);
223
+
224
+ rb_define_method(cPriorityQueue, "initialize", frt_priq_init, 1);
225
+ rb_define_method(cPriorityQueue, "pop", frt_priq_pop, 0);
226
+ rb_define_method(cPriorityQueue, "top", frt_priq_top, 0);
227
+ rb_define_method(cPriorityQueue, "clear", frt_priq_clear, 0);
228
+ rb_define_method(cPriorityQueue, "insert", frt_priq_insert, 1);
229
+ rb_define_method(cPriorityQueue, "push", frt_priq_push, 1);
230
+ rb_define_method(cPriorityQueue, "size", frt_priq_size, 0);
231
+ rb_define_method(cPriorityQueue, "adjust_top", frt_priq_adjust_top, 0);
227
232
  }
data/ext/ram_directory.c CHANGED
@@ -1,6 +1,6 @@
1
1
  #include "ferret.h"
2
2
 
3
- ID flush, seek;
3
+ ID flush, seek, id_file, id_pointer;
4
4
 
5
5
  /****************************************************************************
6
6
  *
@@ -33,23 +33,24 @@ frt_rf_alloc(VALUE klass)
33
33
  {
34
34
  RAMFile *rf;
35
35
  byte_t *buf;
36
+ VALUE rrf;
36
37
 
37
- rf = (RAMFile *)ALLOC(RAMFile);
38
- buf = (byte_t *)ALLOC_N(byte_t, BUFFER_SIZE);
39
- rf->buffers = (void **)ALLOC_N(void *, 1);
38
+ rf = ALLOC(RAMFile);
39
+ buf = ALLOC_N(byte_t, BUFFER_SIZE);
40
+ rf->buffers = ALLOC_N(void *, 1);
40
41
  rf->buffers[0] = buf;
41
42
  rf->bufcnt = 1;
42
43
  rf->length = 0;
43
- rf->mtime = rb_funcall(rb_cTime, frt_newobj, 0);
44
+ rf->mtime = rb_funcall(rb_cTime, id_new, 0);
44
45
 
45
- VALUE rrf = Data_Wrap_Struct(klass, frt_rf_mark, frt_rf_free, rf);
46
+ rrf = Data_Wrap_Struct(klass, frt_rf_mark, frt_rf_free, rf);
46
47
  return rrf;
47
48
  }
48
49
 
49
50
  void
50
51
  frt_rf_extend(RAMFile *rf)
51
52
  {
52
- byte_t *buf = (byte_t *)ALLOC_N(byte_t, BUFFER_SIZE);
53
+ byte_t *buf = ALLOC_N(byte_t, BUFFER_SIZE);
53
54
  rf->bufcnt++;
54
55
  REALLOC_N(rf->buffers, void *, rf->bufcnt);
55
56
  rf->buffers[rf->bufcnt - 1] = buf;
@@ -73,17 +74,17 @@ frt_rf_length(VALUE self)
73
74
  static VALUE
74
75
  frt_rio_init(VALUE self, VALUE ramfile)
75
76
  {
76
- rb_iv_set(self, "file", ramfile);
77
- rb_iv_set(self, "pointer", INT2FIX(0));
77
+ rb_ivar_set(self, id_file, ramfile);
78
+ rb_ivar_set(self, id_pointer, INT2FIX(0));
78
79
  return self;
79
80
  }
80
81
 
81
82
  static VALUE
82
83
  frt_rio_length(VALUE self)
83
84
  {
84
- VALUE file = rb_iv_get(self, "file");
85
+ VALUE file = rb_ivar_get(self, id_file);
85
86
  RAMFile *rf;
86
- Data_Get_Struct(file, RAMFile, rf);
87
+ Data_Get_Struct(file, RAMFile, rf);
87
88
  return INT2FIX(rf->length);
88
89
  }
89
90
 
@@ -102,11 +103,12 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
102
103
  int src_offset;
103
104
  int len = FIX2INT(rlen);
104
105
  /* char *src = StringValuePtr(rsrc); */
105
- int pointer = FIX2INT(rb_iv_get(self, "pointer"));
106
+ int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
107
+ byte_t *buffer;
106
108
 
107
- VALUE file = rb_iv_get(self, "file");
109
+ VALUE file = rb_ivar_get(self, id_file);
108
110
  RAMFile *rf;
109
- Data_Get_Struct(file, RAMFile, rf);
111
+ Data_Get_Struct(file, RAMFile, rf);
110
112
 
111
113
  buffer_number = (int)(pointer / BUFFER_SIZE);
112
114
  buffer_offset = pointer % BUFFER_SIZE;
@@ -115,7 +117,7 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
115
117
 
116
118
  frt_extend_buffer_if_necessary(rf, buffer_number);
117
119
 
118
- byte_t *buffer = rf->buffers[buffer_number];
120
+ buffer = rf->buffers[buffer_number];
119
121
  MEMCPY(buffer + buffer_offset, RSTRING(rsrc)->ptr, byte_t, bytes_to_copy);
120
122
 
121
123
  if (bytes_to_copy < len) {
@@ -128,12 +130,12 @@ frt_rio_flush_buffer(VALUE self, VALUE rsrc, VALUE rlen)
128
130
  MEMCPY(buffer, RSTRING(rsrc)->ptr + src_offset, byte_t, bytes_to_copy);
129
131
  }
130
132
  pointer += len;
131
- rb_iv_set(self, "pointer", INT2FIX(pointer));
133
+ rb_ivar_set(self, id_pointer, INT2FIX(pointer));
132
134
 
133
135
  if (pointer > rf->length)
134
136
  rf->length = pointer;
135
137
 
136
- rf->mtime = rb_funcall(rb_cTime, frt_newobj, 0);
138
+ rf->mtime = rb_class_new_instance(0, NULL, rb_cTime);
137
139
  return Qnil;
138
140
  }
139
141
 
@@ -142,7 +144,7 @@ frt_rio_seek(VALUE self, VALUE rpos)
142
144
  {
143
145
  rb_call_super(1, &rpos);
144
146
 
145
- rb_iv_set(self, "pointer", rpos);
147
+ rb_ivar_set(self, id_pointer, rpos);
146
148
 
147
149
  return rpos;
148
150
  }
@@ -150,24 +152,23 @@ frt_rio_seek(VALUE self, VALUE rpos)
150
152
  static VALUE
151
153
  frt_rio_reset(VALUE self)
152
154
  {
153
- VALUE file = rb_iv_get(self, "file");
155
+ VALUE file = rb_ivar_get(self, id_file);
154
156
  RAMFile *rf;
155
- Data_Get_Struct(file, RAMFile, rf);
156
-
157
- rf->length = 0;
157
+ Data_Get_Struct(file, RAMFile, rf);
158
158
 
159
159
  rb_funcall(self, seek, 1, INT2FIX(0));
160
160
 
161
+ rf->length = 0;
161
162
  return Qnil;
162
163
  }
163
164
 
164
165
  static VALUE
165
166
  frt_rio_close(VALUE self)
166
167
  {
167
- VALUE file = rb_iv_get(self, "file");
168
+ VALUE file = rb_ivar_get(self, id_file);
168
169
  RAMFile *rf;
169
- Data_Get_Struct(file, RAMFile, rf);
170
- rf->mtime = rb_funcall(rb_cTime, frt_newobj, 0);
170
+ Data_Get_Struct(file, RAMFile, rf);
171
+ rf->mtime = rb_funcall(rb_cTime, id_new, 0);
171
172
  rb_call_super(0, NULL);
172
173
  return Qnil;
173
174
  }
@@ -176,14 +177,15 @@ static VALUE
176
177
  frt_rio_write_to(VALUE self, VALUE routput)
177
178
  {
178
179
  int i, len;
179
- VALUE file = rb_iv_get(self, "file");
180
+ int last_buffer_number, last_buffer_offset;
181
+ VALUE file = rb_ivar_get(self, id_file);
180
182
  RAMFile *rf;
181
- Data_Get_Struct(file, RAMFile, rf);
183
+ Data_Get_Struct(file, RAMFile, rf);
182
184
 
183
185
  rb_funcall(self, flush, 0);
184
186
 
185
- int last_buffer_number = (int)(rf->length / BUFFER_SIZE);
186
- int last_buffer_offset = rf->length % BUFFER_SIZE;
187
+ last_buffer_number = (int)(rf->length / BUFFER_SIZE);
188
+ last_buffer_offset = rf->length % BUFFER_SIZE;
187
189
 
188
190
  for (i = 0; i < rf->bufcnt; i++) {
189
191
  len = ((i == last_buffer_number) ? last_buffer_offset : BUFFER_SIZE);
@@ -202,36 +204,36 @@ frt_rio_write_to(VALUE self, VALUE routput)
202
204
  static VALUE
203
205
  frt_rii_init(VALUE self, VALUE ramfile)
204
206
  {
205
- rb_iv_set(self, "file", ramfile);
206
- rb_iv_set(self, "pointer", INT2FIX(0));
207
+ rb_ivar_set(self, id_file, ramfile);
208
+ rb_ivar_set(self, id_pointer, INT2FIX(0));
207
209
  return self;
208
210
  }
209
211
 
210
212
  static VALUE
211
213
  frt_rii_length(VALUE self)
212
214
  {
213
- VALUE file = rb_iv_get(self, "file");
215
+ VALUE file = rb_ivar_get(self, id_file);
214
216
  RAMFile *rf;
215
- Data_Get_Struct(file, RAMFile, rf);
217
+ Data_Get_Struct(file, RAMFile, rf);
216
218
  return INT2FIX(rf->length);
217
219
  }
218
220
 
219
221
  static VALUE
220
222
  frt_rii_read_internal(VALUE self, VALUE rb, VALUE roffset, VALUE rlen)
221
223
  {
222
- VALUE file = rb_iv_get(self, "file");
223
- RAMFile *rf;
224
- Data_Get_Struct(file, RAMFile, rf);
225
-
226
224
  int buffer_number, buffer_offset, bytes_in_buffer, bytes_to_copy;
227
225
  int offset = FIX2INT(roffset);
228
226
  int len = FIX2INT(rlen);
229
227
  int remainder = len;
230
- int pointer = FIX2INT(rb_iv_get(self, "pointer"));
228
+ int pointer = FIX2INT(rb_ivar_get(self, id_pointer));
231
229
  int start = pointer;
232
230
  byte_t *buffer;
233
231
  byte_t *b = (byte_t *)StringValuePtr(rb);
234
232
 
233
+ VALUE file = rb_ivar_get(self, id_file);
234
+ RAMFile *rf;
235
+ Data_Get_Struct(file, RAMFile, rf);
236
+
235
237
  while (remainder > 0) {
236
238
  buffer_number = (int)(start / BUFFER_SIZE);
237
239
  buffer_offset = start % BUFFER_SIZE;
@@ -249,14 +251,14 @@ frt_rii_read_internal(VALUE self, VALUE rb, VALUE roffset, VALUE rlen)
249
251
  remainder -= bytes_to_copy;
250
252
  }
251
253
 
252
- rb_iv_set(self, "pointer", INT2FIX(pointer + len));
254
+ rb_ivar_set(self, id_pointer, INT2FIX(pointer + len));
253
255
  return Qnil;
254
256
  }
255
257
 
256
258
  static VALUE
257
259
  frt_rii_seek_internal(VALUE self, VALUE rpos)
258
260
  {
259
- rb_iv_set(self, "pointer", rpos);
261
+ rb_ivar_set(self, id_pointer, rpos);
260
262
  return Qnil;
261
263
  }
262
264
 
@@ -275,16 +277,19 @@ frt_rii_close(VALUE self)
275
277
  void
276
278
  Init_ram_directory(void)
277
279
  {
280
+ VALUE cDirectory, cRAMFile;
278
281
  /* IDs */
279
282
  flush = rb_intern("flush");
280
283
  seek = rb_intern("seek");
284
+ id_file = rb_intern("@file");
285
+ id_pointer = rb_intern("@pointer");
281
286
 
282
287
  /* RAMDirectory */
283
- VALUE cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
288
+ cDirectory = rb_define_class_under(mStore, "Directory", rb_cObject);
284
289
  cRAMDirectory = rb_define_class_under(mStore, "RAMDirectory", cDirectory);
285
290
 
286
291
  /* RAMFile */
287
- VALUE cRAMFile = rb_define_class_under(cRAMDirectory, "RAMFile", rb_cObject);
292
+ cRAMFile = rb_define_class_under(cRAMDirectory, "RAMFile", rb_cObject);
288
293
  rb_define_alloc_func(cRAMFile, frt_rf_alloc);
289
294
 
290
295
  /* Methods */