summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTomasz Dąbrowski <[email protected]>2016-11-16 17:43:55 +0100
committerYukihiro "Matz" Matsumoto <[email protected]>2016-11-17 17:19:49 +0900
commit4cca8bac6bbdab02eba11e6527f793f2e9a5e75d (patch)
tree6b08ca177e1ebeaa0be3d87a993b27fbe58f795e /include
parent784e07f902790dd13d33460d7365a2f0aee85727 (diff)
downloadmruby-4cca8bac6bbdab02eba11e6527f793f2e9a5e75d.tar.gz
mruby-4cca8bac6bbdab02eba11e6527f793f2e9a5e75d.zip
inline structures data type for mruby (MRB_TT_INLINE) (fix #3237)
Inline structures have no instance variables, no finalizer, and offer as much space as possible in RBASIC object. This means 24 bytes on 64-bit platforms and 12 bytes on 32-bit platforms. mruby-inline-struct gem is only provided for testing.
Diffstat (limited to 'include')
-rw-r--r--include/mruby/inline.h47
-rw-r--r--include/mruby/value.h3
2 files changed, 49 insertions, 1 deletions
diff --git a/include/mruby/inline.h b/include/mruby/inline.h
new file mode 100644
index 000000000..e773aa118
--- /dev/null
+++ b/include/mruby/inline.h
@@ -0,0 +1,47 @@
+/*
+** mruby/inline.h - Inline structures
+**
+** See Copyright Notice in mruby.h
+*/
+
+#ifndef MRUBY_INLINE_H
+#define MRUBY_INLINE_H
+
+#include "common.h"
+#include <string.h>
+
+/**
+ * Inline structures that fit in RVALUE
+ *
+ * They cannot have finalizer, and cannot have instance variables.
+ */
+MRB_BEGIN_DECL
+
+#define INLINE_DATA_SIZE (sizeof(void*) * 3)
+
+struct RInline {
+ MRB_OBJECT_HEADER;
+ char inline_data[INLINE_DATA_SIZE];
+};
+
+#define RINLINE(obj) ((struct RInline*)(mrb_ptr(obj)))
+#define INLINE_PTR(obj) (RINLINE(obj)->inline_data)
+
+MRB_INLINE mrb_int mrb_inline_size()
+{
+ return INLINE_DATA_SIZE;
+}
+
+MRB_INLINE void* mrb_inline_ptr(mrb_value object)
+{
+ return INLINE_PTR(object);
+}
+
+MRB_INLINE void mrb_inline_copy(mrb_value dest, mrb_value src)
+{
+ memcpy(INLINE_PTR(dest), INLINE_PTR(src), INLINE_DATA_SIZE);
+}
+
+MRB_END_DECL
+
+#endif /* MRUBY_INLINE_H */
diff --git a/include/mruby/value.h b/include/mruby/value.h
index 4330b9441..eb3f931e1 100644
--- a/include/mruby/value.h
+++ b/include/mruby/value.h
@@ -116,7 +116,8 @@ enum mrb_vtype {
MRB_TT_ENV, /* 20 */
MRB_TT_DATA, /* 21 */
MRB_TT_FIBER, /* 22 */
- MRB_TT_MAXDEFINE /* 23 */
+ MRB_TT_INLINE, /* 23 */
+ MRB_TT_MAXDEFINE /* 24 */
};
#include <mruby/object.h>