diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/string.h | 27 |
1 files changed, 18 insertions, 9 deletions
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*); |
