summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMasaki Muranaka <[email protected]>2013-03-19 01:53:15 +0900
committerMasaki Muranaka <[email protected]>2013-03-23 12:30:53 +0900
commit2a341753f888d411851e4c30ecd0f2245c275633 (patch)
treeef976e26fb40a854ed6e456b4dd8bd4fc9c3f2ba /src
parentacab35a2a54e00e197b7372e940b83235480179d (diff)
downloadmruby-2a341753f888d411851e4c30ecd0f2245c275633.tar.gz
mruby-2a341753f888d411851e4c30ecd0f2245c275633.zip
Make array.c and vm.c share value_move().
Diffstat (limited to 'src')
-rw-r--r--src/array.c7
-rw-r--r--src/value_array.h27
-rw-r--r--src/vm.c22
3 files changed, 32 insertions, 24 deletions
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 <string.h>
#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 <string.h>
#include <setjmp.h>
@@ -55,27 +56,6 @@ The value below allows about 60000 recursive calls in the simplest case. */
#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)
{
const mrb_value mrb_value_zero = { { 0 } };