summaryrefslogtreecommitdiff
path: root/ruby.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-05 14:40:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-05 14:40:01 +0000
commited0fd0279617024a608a8ee4c1aa931db61e92c4 (patch)
tree81352865082b7b567c9d8185de9bfc40bed82aaf /ruby.h
parent2746f3352b0b6854420529a6432167b4cf03c13f (diff)
* ruby.h (struct RStruct): embed 3 or less elements structs.
(RSTRUCT_LEN): defined for accessing struct members. (RSTRUCT_PTR): ditto. * struct.c: use RSTRUCT_LEN and RSTRUCT_PTR. (struct_alloc): allocate small structs in embedded format. (rb_struct_init_copy): ditto. * gc.c (gc_mark_children): use RSTRUCT_LEN and RSTRUCT_PTR. (obj_free): ditto. * marshal.c (w_object): use RSTRUCT_LEN and RSTRUCT_PTR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.h')
-rw-r--r--ruby.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/ruby.h b/ruby.h
index 36b146dd46..4244cd4ee4 100644
--- a/ruby.h
+++ b/ruby.h
@@ -417,11 +417,27 @@ VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
sval = (type*)DATA_PTR(obj);\
} while (0)
+#define RSTRUCT_EMBED_LEN_MAX 3
struct RStruct {
struct RBasic basic;
- long len;
- VALUE *ptr;
+ union {
+ struct {
+ long len;
+ VALUE *ptr;
+ } heap;
+ VALUE ary[RSTRUCT_EMBED_LEN_MAX];
+ } as;
};
+#define RSTRUCT_EMBED_LEN_MASK (FL_USER1|FL_USER0)
+#define RSTRUCT_EMBED_LEN_SHIFT FL_USHIFT
+#define RSTRUCT_LEN(st) \
+ ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
+ (RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & 3 : \
+ RSTRUCT(st)->as.heap.len)
+#define RSTRUCT_PTR(st) \
+ ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
+ RSTRUCT(st)->as.ary : \
+ RSTRUCT(st)->as.heap.ptr)
struct RBignum {
struct RBasic basic;