summaryrefslogtreecommitdiffhomepage
path: root/src/value_array.h
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-03-23 03:48:11 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-03-23 03:48:11 -0700
commit66bd53a4152572b35bdf73e39713718fa1a3fc17 (patch)
tree438aec5e0104e0854fe49820ed905c872508c753 /src/value_array.h
parentaf2f3dd16f0d322a4d878196c1b8565cc264d625 (diff)
parent2a341753f888d411851e4c30ecd0f2245c275633 (diff)
downloadmruby-66bd53a4152572b35bdf73e39713718fa1a3fc17.tar.gz
mruby-66bd53a4152572b35bdf73e39713718fa1a3fc17.zip
Merge pull request #1048 from monaka/pr-make-array.c-and-vm.c-share-value_move
Make array.c and vm.c share value_move().
Diffstat (limited to 'src/value_array.h')
-rw-r--r--src/value_array.h27
1 files changed, 27 insertions, 0 deletions
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__ */