|
31 | 31 | # define RSTRING_LEN(v) RSTRING(v)->len |
32 | 32 | #endif |
33 | 33 |
|
34 | | -#ifndef RARRAY_PTR |
35 | | -# define RARRAY_PTR(v) RARRAY(v)->ptr |
36 | | -#endif |
37 | | - |
38 | 34 | #ifndef RARRAY_LEN |
39 | 35 | # define RARRAY_LEN(v) RARRAY(v)->len |
40 | 36 | #endif |
@@ -311,13 +307,12 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) { |
311 | 307 | } |
312 | 308 |
|
313 | 309 | items = RARRAY_LEN(value); |
314 | | - values = RARRAY_PTR(value); |
315 | 310 | for(i = 0; i < items; i++) { |
316 | 311 | char* name; |
317 | 312 | VALUE key; |
318 | 313 | INT2STRING(&name, i); |
319 | 314 | key = rb_str_new2(name); |
320 | | - write_element_with_id(key, values[i], pack_extra(buffer, check_keys)); |
| 315 | + write_element_with_id(key, rb_ary_entry(value, i), pack_extra(buffer, check_keys)); |
321 | 316 | free(name); |
322 | 317 | } |
323 | 318 |
|
@@ -398,7 +393,7 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) { |
398 | 393 | int i; |
399 | 394 | write_name_and_type(buffer, key, 0x07); |
400 | 395 | for (i = 0; i < 12; i++) { |
401 | | - char byte = (char)FIX2INT(RARRAY_PTR(as_array)[i]); |
| 396 | + char byte = (char)FIX2INT(rb_ary_entry(as_array, i)); |
402 | 397 | SAFE_WRITE(buffer, &byte, 1); |
403 | 398 | } |
404 | 399 | break; |
@@ -571,7 +566,7 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_ |
571 | 566 | VALUE keys = rb_funcall(hash, rb_intern("keys"), 0); |
572 | 567 | int i; |
573 | 568 | for(i = 0; i < RARRAY_LEN(keys); i++) { |
574 | | - VALUE key = RARRAY_PTR(keys)[i]; |
| 569 | + VALUE key = rb_ary_entry(keys, i); |
575 | 570 | VALUE value = rb_hash_aref(hash, key); |
576 | 571 |
|
577 | 572 | write_function(key, value, pack_extra(buffer, check_keys)); |
@@ -877,16 +872,19 @@ static VALUE method_deserialize(VALUE self, VALUE bson) { |
877 | 872 | static VALUE fast_pack(VALUE self) |
878 | 873 | { |
879 | 874 | VALUE res; |
880 | | - long i; |
| 875 | + long i, len; |
881 | 876 | char c; |
| 877 | + char *buf; |
882 | 878 |
|
883 | | - res = rb_str_buf_new(0); |
| 879 | + len = RARRAY_LEN(self); |
| 880 | + buf = malloc(len * sizeof(char)); |
884 | 881 |
|
885 | | - for (i = 0; i < RARRAY_LEN(self); i++) { |
886 | | - c = FIX2LONG(RARRAY_PTR(self)[i]); |
887 | | - rb_str_buf_cat(res, &c, sizeof(char)); |
| 882 | + for (i = 0; i < len; i++) { |
| 883 | + buf[i] = FIX2INT(rb_ary_entry(self, i)); |
888 | 884 | } |
889 | 885 |
|
| 886 | + res = rb_str_new(buf, len); |
| 887 | + |
890 | 888 | return res; |
891 | 889 | } |
892 | 890 |
|
|
0 commit comments