Commit 0f2b6964 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #302 from monaka/pr-remove-strlen-in-array

Remove strlen in array
parents 178a1a63 0c5b704d
...@@ -880,9 +880,9 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) ...@@ -880,9 +880,9 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
{ {
int i; int i;
mrb_value s, arystr; mrb_value s, arystr;
char *head = "["; char head[] = { '[' };
char *sep = ", "; char sep[] = { ',', ' ' };
char *tail = "]"; char tail[] = { ']' };
/* check recursive */ /* check recursive */
for(i=0; i<RARRAY_LEN(list); i++) { for(i=0; i<RARRAY_LEN(list); i++) {
...@@ -894,13 +894,13 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) ...@@ -894,13 +894,13 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
mrb_ary_push(mrb, list, ary); mrb_ary_push(mrb, list, ary);
arystr = mrb_str_buf_new(mrb, 64); arystr = mrb_str_buf_new(mrb, 64);
mrb_str_buf_cat(mrb, arystr, head, strlen(head)); mrb_str_buf_cat(mrb, arystr, head, sizeof(head));
for(i=0; i<RARRAY_LEN(ary); i++) { for(i=0; i<RARRAY_LEN(ary); i++) {
int ai = mrb_gc_arena_save(mrb); int ai = mrb_gc_arena_save(mrb);
if (i > 0) { if (i > 0) {
mrb_str_buf_cat(mrb, arystr, sep, strlen(sep)); mrb_str_buf_cat(mrb, arystr, sep, sizeof(sep));
} }
if (mrb_type(RARRAY_PTR(ary)[i]) == MRB_TT_ARRAY) { if (mrb_type(RARRAY_PTR(ary)[i]) == MRB_TT_ARRAY) {
s = inspect_ary(mrb, RARRAY_PTR(ary)[i], list); s = inspect_ary(mrb, RARRAY_PTR(ary)[i], list);
...@@ -911,7 +911,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list) ...@@ -911,7 +911,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
mrb_gc_arena_restore(mrb, ai); mrb_gc_arena_restore(mrb, ai);
} }
mrb_str_buf_cat(mrb, arystr, tail, strlen(tail)); mrb_str_buf_cat(mrb, arystr, tail, sizeof(tail));
mrb_ary_pop(mrb, list); mrb_ary_pop(mrb, list);
return arystr; return arystr;
......
...@@ -234,4 +234,12 @@ assert('Array#unshift', '15.2.12.5.30') do ...@@ -234,4 +234,12 @@ assert('Array#unshift', '15.2.12.5.30') do
a == [1,2,3] and b == [1,2,3] a == [1,2,3] and b == [1,2,3]
end end
assert('Array#to_s', '15.2.12.5.31') do
a = [2, 3, 4, 5]
r1 = a.to_s
r2 = a.inspect
r1 == r2 and r1 == "[2, 3, 4, 5]"
end
# Not ISO specified # Not ISO specified
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment