mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
4cca8bac6b
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.
48 lines
878 B
C
48 lines
878 B
C
/*
|
|
** 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 */
|