summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2012-06-21 00:10:33 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2012-06-21 00:10:33 -0700
commit0f2b69642d589aa5a55de7b4807d9b3072e4cc52 (patch)
tree73d779862d812a9cc1af8dd5469cc1fd9a72af84
parent178a1a63f960188c8d76e14983f75c4e1b346db2 (diff)
parent0c5b704de355d021f73af72ff4050485fe4203ec (diff)
downloadmruby-0f2b69642d589aa5a55de7b4807d9b3072e4cc52.tar.gz
mruby-0f2b69642d589aa5a55de7b4807d9b3072e4cc52.zip
Merge pull request #302 from monaka/pr-remove-strlen-in-array
Remove strlen in array
-rw-r--r--src/array.c12
-rw-r--r--test/t/array.rb8
2 files changed, 14 insertions, 6 deletions
diff --git a/src/array.c b/src/array.c
index 3b42abc74..ca111bc0e 100644
--- a/src/array.c
+++ b/src/array.c
@@ -880,9 +880,9 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
{
int i;
mrb_value s, arystr;
- char *head = "[";
- char *sep = ", ";
- char *tail = "]";
+ char head[] = { '[' };
+ char sep[] = { ',', ' ' };
+ char tail[] = { ']' };
/* check recursive */
for(i=0; i<RARRAY_LEN(list); i++) {
@@ -894,13 +894,13 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
mrb_ary_push(mrb, list, ary);
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++) {
int ai = mrb_gc_arena_save(mrb);
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) {
s = inspect_ary(mrb, RARRAY_PTR(ary)[i], list);
@@ -911,7 +911,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
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);
return arystr;
diff --git a/test/t/array.rb b/test/t/array.rb
index 1cfe02af7..3f441c1cc 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -234,4 +234,12 @@ assert('Array#unshift', '15.2.12.5.30') do
a == [1,2,3] and b == [1,2,3]
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