mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
embed small string
use flags 4 for *this object is embed* use flags 8~64 for *embed string length*
This commit is contained in:
+18
-9
@@ -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*);
|
||||
|
||||
Reference in New Issue
Block a user