diff options
| author | ksss <[email protected]> | 2014-03-05 15:06:29 +0000 |
|---|---|---|
| committer | ksss <[email protected]> | 2014-03-06 13:47:51 +0000 |
| commit | 54132e436494b4797ca53cbd934963e7d752ac42 (patch) | |
| tree | c490aee6faa4fbcc8aac66b205b5087af4c208bc /include | |
| parent | 4070b5987a76a2d633a99e137035749559e2da59 (diff) | |
| download | mruby-54132e436494b4797ca53cbd934963e7d752ac42.tar.gz mruby-54132e436494b4797ca53cbd934963e7d752ac42.zip | |
make embed string when create literals
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/string.h | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/include/mruby/string.h b/include/mruby/string.h index 27798b091..7e7fb13d9 100644 --- a/include/mruby/string.h +++ b/include/mruby/string.h @@ -15,7 +15,15 @@ extern "C" { extern const char mrb_digitmap[]; -#define RSTRING_EMBED_LEN_MAX ((mrb_int)((sizeof(mrb_int)*2+sizeof(char*))/sizeof(char)-1)) +/* (sizeof(mrb_int)*2+sizeof(char*))/sizeof(char)-1 */ +#if defined(MRB_INT16) +# define RSTRING_EMBED_LEN_MAX 9 +#elif defined(MRB_INT64) +# define RSTRING_EMBED_LEN_MAX 15 +#else +# define RSTRING_EMBED_LEN_MAX 11 +#endif + struct RString { MRB_OBJECT_HEADER; union { @@ -33,10 +41,19 @@ struct RString { #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) #define RSTRING(s) ((struct RString*)(mrb_ptr(s))) -#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 RSTRING_PTR(s)\ + ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ + RSTRING(s)->as.ary :\ + RSTRING(s)->as.heap.ptr) +#define RSTRING_LEN(s)\ + ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ + (mrb_int)((RSTRING(s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) :\ + RSTRING(s)->as.heap.len) +#define RSTRING_CAPA(s)\ + ((RSTRING(s)->flags & MRB_STR_EMBED) ?\ + RSTRING_EMBED_LEN_MAX :\ + RSTRING(s)->as.heap.aux.capa) +#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) #define MRB_STR_SHARED 1 #define MRB_STR_NOFREE 2 |
