embed small string

use flags 4 for *this object is embed*
use flags 8~64 for *embed string length*
This commit is contained in:
ksss
2014-03-02 11:04:04 +00:00
parent e40428af7b
commit 4070b5987a
11 changed files with 210 additions and 181 deletions
+18 -9
View File
@@ -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*);