mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
784e07f902
commit
4cca8bac6b
@@ -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 */
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user