diff options
| author | ksss <[email protected]> | 2014-03-02 11:04:04 +0000 |
|---|---|---|
| committer | ksss <[email protected]> | 2014-03-06 13:12:08 +0000 |
| commit | 4070b5987a76a2d633a99e137035749559e2da59 (patch) | |
| tree | 0a753936d9fc52112b1e9c8f2e623a0542afc298 /include | |
| parent | e40428af7b02870663a6c052496c176c22c5e875 (diff) | |
| download | mruby-4070b5987a76a2d633a99e137035749559e2da59.tar.gz mruby-4070b5987a76a2d633a99e137035749559e2da59.zip | |
embed small string
use flags 4 for *this object is embed*
use flags 8~64 for *embed string length*
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*); |
