From 2156870525be05f0bd769af141c3f6cff9fff8c4 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 2 Sep 2006 14:42:08 +0000 Subject: * ruby.h (struct RArray): embed small arrays. (RARRAY_LEN): defined for accessing array members. (RARRAY_PTR): ditto. * array.c: use RARRAY_LEN and RARRAY_PTR. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby.h | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'ruby.h') diff --git a/ruby.h b/ruby.h index 6a2d2db4c0..b9943fdd80 100644 --- a/ruby.h +++ b/ruby.h @@ -390,15 +390,33 @@ struct RString { RSTRING(str)->as.ary : \ RSTRING(str)->as.heap.ptr) +#define RARRAY_EMBED_LEN_MAX 3 struct RArray { struct RBasic basic; - long len; union { - long capa; - VALUE shared; - } aux; - VALUE *ptr; + struct { + long len; + union { + long capa; + VALUE shared; + } aux; + VALUE *ptr; + } heap; + VALUE ary[RARRAY_EMBED_LEN_MAX]; + } as; }; +#define RARRAY_NOEMBED FL_USER3 +#define RARRAY_EMBED_LEN_MASK (FL_USER4|FL_USER5) +#define RARRAY_EMBED_LEN_SHIFT (FL_USHIFT+4) +#define RARRAY_LEN(a) \ + (!(RBASIC(a)->flags & RARRAY_NOEMBED) ? \ + (long)((RBASIC(a)->flags >> RARRAY_EMBED_LEN_SHIFT) & \ + (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)) : \ + RARRAY(a)->as.heap.len) +#define RARRAY_PTR(a) \ + (!(RBASIC(a)->flags & RARRAY_NOEMBED) ? \ + RARRAY(a)->as.ary : \ + RARRAY(a)->as.heap.ptr) struct RRegexp { struct RBasic basic; -- cgit v1.2.3