From 4070b5987a76a2d633a99e137035749559e2da59 Mon Sep 17 00:00:00 2001 From: ksss Date: Sun, 2 Mar 2014 11:04:04 +0000 Subject: embed small string use flags 4 for *this object is embed* use flags 8~64 for *embed string length* --- include/mruby/string.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/mruby/string.h b/include/mruby/string.h index 966f0bf77..27798b091 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -15,25 +15,34 @@ extern "C" { extern const char mrb_digitmap[]; +#define RSTRING_EMBED_LEN_MAX ((mrb_int)((sizeof(mrb_int)*2+sizeof(char*))/sizeof(char)-1)) struct RString { MRB_OBJECT_HEADER; - mrb_int len; union { - mrb_int capa; - struct mrb_shared_string *shared; - } aux; - char *ptr; + struct { + mrb_int len; + union { + mrb_int capa; + struct mrb_shared_string *shared; + } aux; + char *ptr; + } heap; + char ary[RSTRING_EMBED_LEN_MAX + 1]; + } as; }; #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) #define RSTRING(s) ((struct RString*)(mrb_ptr(s))) -#define RSTRING_PTR(s) (RSTRING(s)->ptr) -#define RSTRING_LEN(s) (RSTRING(s)->len) -#define RSTRING_CAPA(s) (RSTRING(s)->aux.capa) -#define RSTRING_END(s) (RSTRING(s)->ptr + RSTRING(s)->len) +#define RSTRING_PTR(s) (RSTRING(s)->as.heap.ptr) +#define RSTRING_LEN(s) (RSTRING(s)->as.heap.len) +#define RSTRING_CAPA(s) (RSTRING(s)->as.heap.aux.capa) +#define RSTRING_END(s) (RSTRING(s)->as.heap.ptr + RSTRING(s)->as.heap.len) #define MRB_STR_SHARED 1 #define MRB_STR_NOFREE 2 +#define MRB_STR_EMBED 4 +#define MRB_STR_EMBED_LEN_MASK 120 +#define MRB_STR_EMBED_LEN_SHIFT 3 void mrb_gc_free_str(mrb_state*, struct RString*); void mrb_str_modify(mrb_state*, struct RString*); -- cgit v1.2.3