Commit 21f2e536 authored by Masaki Muranaka's avatar Masaki Muranaka

Use mrb_str_new() instead of mrb_str_new2() as possible.

parent 8946ad2c
......@@ -887,7 +887,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
/* check recursive */
for(i=0; i<RARRAY_LEN(list); i++) {
if (mrb_obj_equal(mrb, ary, RARRAY_PTR(list)[i])) {
return mrb_str_new2(mrb, "[...]");
return mrb_str_new(mrb, "[...]", 5);
}
}
......@@ -929,7 +929,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
static mrb_value
mrb_ary_inspect(mrb_state *mrb, mrb_value ary)
{
if (RARRAY_LEN(ary) == 0) return mrb_str_new2(mrb, "[]");
if (RARRAY_LEN(ary) == 0) return mrb_str_new(mrb, "[]", 2);
#if 0 /* THREAD */
return mrb_exec_recursive(inspect_ary_r, ary, 0);
#else
......
......@@ -15,6 +15,7 @@
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <assert.h>
#if defined(__FreeBSD__) && __FreeBSD__ < 4
#include <floatingpoint.h>
......@@ -186,15 +187,21 @@ static mrb_value
flo_to_s(mrb_state *mrb, mrb_value flt)
{
char buf[32];
int n;
mrb_float value = mrb_float(flt);
if (isinf(value))
return mrb_str_new2(mrb, value < 0 ? "-inf" : "inf");
else if(isnan(value))
return mrb_str_new2(mrb, "NaN");
sprintf(buf, "%.14g", value);
return mrb_str_new2(mrb, buf);
if (isinf(value)) {
static const char s[2][5] = { "-inf", "inf" };
static const int n[] = { 4, 3 };
int idx;
idx = (value < 0) ? 0 : 1;
return mrb_str_new(mrb, s[idx], n[idx]);
} else if(isnan(value))
return mrb_str_new(mrb, "NaN", 3);
n = sprintf(buf, "%.14g", value);
assert(n >= 0);
return mrb_str_new(mrb, buf, n);
}
/* 15.2.9.3.2 */
......@@ -1158,7 +1165,7 @@ mrb_fix2str(mrb_state *mrb, mrb_value x, int base)
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid radix %d", base);
}
if (val == 0) {
return mrb_str_new2(mrb, "0");
return mrb_str_new(mrb, "0", 1);
}
if (val < 0) {
val = -val;
......
......@@ -343,7 +343,12 @@ inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur)
struct RRange *r = mrb_range_ptr(range);
if (recur) {
return mrb_str_new2(mrb, r->excl ? "(... ... ...)" : "(... .. ...)");
static const char s[2][14] = { "(... ... ...)", "(... .. ...)" };
static const int n[] = { 13, 12 };
int idx;
idx = (r->excl) ? 0 : 1;
return mrb_str_new(mrb, s[idx], n[idx]);
}
str = mrb_inspect(mrb, r->edges->beg);
str2 = mrb_inspect(mrb, r->edges->end);
......
......@@ -89,7 +89,7 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
val &= 0x3ff;
if (val == 0) {
return mrb_str_new2(mrb, "0");
return mrb_str_new(mrb, "0", 1);
}
*--b = '\0';
do {
......
......@@ -21,6 +21,7 @@
#include "regex.h"
#include "st.h"
#endif //ENABLE_REGEXP
#include <assert.h>
const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
......@@ -220,7 +221,9 @@ mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, int len)
mrb_value
mrb_str_new(mrb_state *mrb, const char *p, int len)
{
struct RString *s = str_new(mrb, p, len);
struct RString *s;
assert(!(!p && len));
s = str_new(mrb, p, len);
return mrb_obj_value(s);
}
......@@ -1969,7 +1972,7 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start)
if (regs->num_regs == 1) {
return mrb_reg_nth_match(mrb, 0, match);
}
result = mrb_ary_new_capa(mrb, regs->num_regs);//mrb_ary_new2(regs->num_regs);
result = mrb_ary_new_capa(mrb, regs->num_regs);
for (i=1; i < regs->num_regs; i++) {
mrb_ary_push(mrb, result, mrb_reg_nth_match(mrb, i, match));
}
......
......@@ -93,7 +93,7 @@ mrb_struct_s_members_m(mrb_state *mrb, mrb_value klass)
mrb_value *p, *pend;
members = mrb_struct_s_members(mrb, klass);
ary = mrb_ary_new_capa(mrb, RARRAY_LEN(members));//mrb_ary_new2(RARRAY_LEN(members));
ary = mrb_ary_new_capa(mrb, RARRAY_LEN(members));
p = RARRAY_PTR(members); pend = p + RARRAY_LEN(members);
while (p < pend) {
mrb_ary_push(mrb, ary, *p);
......@@ -493,7 +493,7 @@ static mrb_value
inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur)
{
const char *cn = mrb_class_name(mrb, mrb_obj_class(mrb, s));
mrb_value members, str = mrb_str_new2(mrb, "#<struct ");
mrb_value members, str = mrb_str_new(mrb, "#<struct ", 9);
mrb_value *ptr, *ptr_members;
long i, len;
......
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