From 2a341753f888d411851e4c30ecd0f2245c275633 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 19 Mar 2013 01:53:15 +0900 Subject: Make array.c and vm.c share value_move(). --- src/array.c | 7 ++++--- src/value_array.h | 27 +++++++++++++++++++++++++++ src/vm.c | 22 +--------------------- 3 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 src/value_array.h (limited to 'src') diff --git a/src/array.c b/src/array.c index bfdb1bb97..61b27a678 100644 --- a/src/array.c +++ b/src/array.c @@ -9,6 +9,7 @@ #include #include "mruby/string.h" #include "mruby/class.h" +#include "value_array.h" /* SIZE_MAX is not supported by VC++. */ #ifndef SIZE_MAX @@ -519,7 +520,7 @@ mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item) ary_modify(mrb, a); if (a->aux.capa < a->len + 1) ary_expand_capa(mrb, a, a->len + 1); - memmove(a->ptr + 1, a->ptr, sizeof(mrb_value)*a->len); + value_move(a->ptr + 1, a->ptr, a->len); a->ptr[0] = item; } a->len++; @@ -546,7 +547,7 @@ mrb_ary_unshift_m(mrb_state *mrb, mrb_value self) if (len == 0) return self; if (a->aux.capa < a->len + len) ary_expand_capa(mrb, a, a->len + len); - memmove(a->ptr + len, a->ptr, sizeof(mrb_value)*a->len); + value_move(a->ptr + len, a->ptr, a->len); } array_copy(a->ptr, vals, len); a->len += len; @@ -631,7 +632,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val ary_fill_with_nil(a->ptr + a->len, (int)(head - a->len)); } else if (head < a->len) { - memmove(a->ptr + head + argc, a->ptr + tail, sizeof(mrb_value)*(a->len - tail)); + value_move(a->ptr + head + argc, a->ptr + tail, a->len - tail); } for(i = 0; i < argc; i++) { diff --git a/src/value_array.h b/src/value_array.h new file mode 100644 index 000000000..cabd2426d --- /dev/null +++ b/src/value_array.h @@ -0,0 +1,27 @@ +#ifndef MRB_VALUE_ARRAY_H__ +#define MRB_VALUE_ARRAY_H__ + +#include "mruby.h" + +static inline void +value_move(mrb_value *s1, const mrb_value *s2, size_t n) +{ + if (s1 > s2 && s1 < s2 + n) + { + s1 += n; + s2 += n; + while (n-- > 0) { + *--s1 = *--s2; + } + } + else if (s1 != s2) { + while (n-- > 0) { + *s1++ = *s2++; + } + } + else { + /* nothing to do. */ + } +} + +#endif /* MRB_VALUE_ARRAY_H__ */ diff --git a/src/vm.c b/src/vm.c index c18054a9c..7dd9d5d6d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -16,6 +16,7 @@ #include "mruby/class.h" #include "mruby/numeric.h" #include "error.h" +#include "value_array.h" #include #include @@ -54,27 +55,6 @@ The value below allows about 60000 recursive calls in the simplest case. */ # define DEBUG(x) #endif -static inline void -value_move(mrb_value *s1, const mrb_value *s2, size_t n) -{ - if (s1 > s2 && s1 < s2 + n) - { - s1 += n; - s2 += n; - while (n-- > 0) { - *--s1 = *--s2; - } - } - else if (s1 != s2) { - while (n-- > 0) { - *s1++ = *s2++; - } - } - else { - /* nothing to do. */ - } -} - static inline void stack_clear(mrb_value *from, size_t count) { -- cgit v1.2.3