summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array.c14
-rw-r--r--src/object.c13
-rw-r--r--src/time.c2
-rw-r--r--src/vm.c17
4 files changed, 17 insertions, 29 deletions
diff --git a/src/array.c b/src/array.c
index 15b6df0f2..fa43bdd35 100644
--- a/src/array.c
+++ b/src/array.c
@@ -37,16 +37,13 @@ ary_new_capa(mrb_state *mrb, int capa)
mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
}
#endif
- if (capa < ARY_DEFAULT_LEN) {
- capa = ARY_DEFAULT_LEN;
- }
blen = capa * sizeof(mrb_value) ;
if (blen < capa) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "ary size too big");
}
a = (struct RArray*)mrb_obj_alloc(mrb, MRB_TT_ARRAY, mrb->array_class);
- a->ptr = (mrb_value *)mrb_calloc(mrb, blen, 1);
+ a->ptr = (mrb_value *)mrb_malloc(mrb, blen);
a->aux.capa = capa;
a->len = 0;
@@ -859,9 +856,11 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self)
{
struct RArray *a = mrb_ary_ptr(self);
- a->len = 0;
ary_modify(mrb, a);
- ary_shrink_capa(mrb, a);
+ a->len = 0;
+ a->aux.capa = 0;
+ mrb_free(mrb, a->ptr);
+ a->ptr = 0;
return self;
}
@@ -1054,7 +1053,8 @@ mrb_ary_equal(mrb_state *mrb, mrb_value ary1)
mrb_value ary2;
mrb_get_args(mrb, "o", &ary2);
- if (mrb_obj_equal(mrb, ary1,ary2)) return mrb_true_value();
+ if (mrb_obj_equal(mrb, ary1, ary2)) return mrb_true_value();
+ if (SPECIAL_CONST_P(ary2)) return mrb_false_value();
if (mrb_type(ary2) != MRB_TT_ARRAY) {
if (!mrb_respond_to(mrb, ary2, mrb_intern(mrb, "to_ary"))) {
return mrb_false_value();
diff --git a/src/object.c b/src/object.c
index 4c494101a..5130f3d54 100644
--- a/src/object.c
+++ b/src/object.c
@@ -47,17 +47,8 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2)
if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE;
result = mrb_funcall(mrb, obj1, "==", 1, obj2);
- if (mrb_nil_p(result)) {
- return FALSE;
- }
- else {
- if (mrb_type(result) == MRB_TT_TRUE) {
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
+ if (mrb_test(result)) return TRUE;
+ return FALSE;
}
/*
diff --git a/src/time.c b/src/time.c
index 3dd56c6a9..085c4f30f 100644
--- a/src/time.c
+++ b/src/time.c
@@ -28,13 +28,11 @@
#ifdef _WIN32
/* Win32 platform do not provide gmtime_r/localtime_r; emulate them using gmtime_s/localtime_s */
-#if _MVC_VER
#define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL)
#define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tm) : NULL)
#else
#define NO_GMTIME_R
#endif
-#endif
/* timegm(3) */
/* mktime() creates tm structure for localtime; timegm() is for UTF time */
diff --git a/src/vm.c b/src/vm.c
index 256ae8ef4..75a4cd442 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1495,7 +1495,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_EQ) {
/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/
- OP_CMP(==);
+ int a = GETARG_A(i);
+ if (mrb_obj_eq(mrb, regs[a], regs[a+1])) {
+ SET_TRUE_VALUE(regs[a]);
+ }
+ else {
+ OP_CMP(==);
+ }
NEXT;
}
@@ -1525,14 +1531,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
CASE(OP_ARRAY) {
/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
- int b = GETARG_B(i);
- int lim = b+GETARG_C(i);
- mrb_value ary = mrb_ary_new_capa(mrb, GETARG_C(i));
-
- while (b < lim) {
- mrb_ary_push(mrb, ary, regs[b++]);
- }
- regs[GETARG_A(i)] = ary;
+ regs[GETARG_A(i)] = mrb_ary_new_from_values(mrb, GETARG_C(i), &regs[GETARG_B(i)]);
mrb->arena_idx = ai;
NEXT;
}