mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* method.h: embed rb_method_entry_t::attr::flags (5 bits) into
rb_method_entry_t::flags to make one word spare space. Add some macros to access these flags. * vm_method.c: use these macros. * internal.h: define IMEMO_FL_USHIFT and IMEMO_FL_USER[0-4] for T_IMEMO local flags. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c7edd997e8
commit
a5fa5f34b0
4 changed files with 59 additions and 21 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Thu Jun 11 08:52:01 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* method.h: embed rb_method_entry_t::attr::flags (5 bits) into
|
||||
rb_method_entry_t::flags to make one word spare space.
|
||||
|
||||
Add some macros to access these flags.
|
||||
|
||||
* vm_method.c: use these macros.
|
||||
|
||||
* internal.h: define IMEMO_FL_USHIFT and IMEMO_FL_USER[0-4]
|
||||
for T_IMEMO local flags.
|
||||
|
||||
Thu Jun 11 08:27:06 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm.c: use VM_ASSERT instead of assert().
|
||||
|
|
|
@ -545,6 +545,14 @@ imemo_type(VALUE imemo)
|
|||
return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
|
||||
}
|
||||
|
||||
/* FL_USER0 to FL_USER2 is for type */
|
||||
#define IMEMO_FL_USHIFT (FL_USHIFT + 3)
|
||||
#define IMEMO_FL_USER0 FL_USER3
|
||||
#define IMEMO_FL_USER1 FL_USER4
|
||||
#define IMEMO_FL_USER2 FL_USER5
|
||||
#define IMEMO_FL_USER3 FL_USER6
|
||||
#define IMEMO_FL_USER4 FL_USER7
|
||||
|
||||
/* CREF in method.h */
|
||||
|
||||
/* SVAR */
|
||||
|
|
46
method.h
46
method.h
|
@ -47,24 +47,44 @@ typedef struct rb_cref_struct {
|
|||
|
||||
typedef struct rb_method_entry_struct {
|
||||
VALUE flags;
|
||||
|
||||
union {
|
||||
struct {
|
||||
rb_method_visibility_t visi: 3;
|
||||
unsigned int safe: 3;
|
||||
unsigned int basic: 1;
|
||||
} flags;
|
||||
VALUE v; /* it should be VALUE size */
|
||||
} attr;
|
||||
|
||||
VALUE dummy;
|
||||
struct rb_method_definition_struct * const def;
|
||||
ID called_id;
|
||||
const VALUE klass; /* should be marked */
|
||||
} rb_method_entry_t;
|
||||
|
||||
#define METHOD_ENTRY_VISI(me) (me)->attr.flags.visi
|
||||
#define METHOD_ENTRY_BASIC(me) (me)->attr.flags.basic
|
||||
#define METHOD_ENTRY_SAFE(me) (me)->attr.flags.safe
|
||||
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
||||
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
||||
#define METHOD_ENTRY_SAFE(me) (int) (((me)->flags & (IMEMO_FL_USER3 | IMEMO_FL_USER4)) >> (IMEMO_FL_USHIFT+3))
|
||||
|
||||
static inline void
|
||||
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
||||
{
|
||||
VM_ASSERT(visi <= 3);
|
||||
me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << IMEMO_FL_USHIFT+0);
|
||||
}
|
||||
static inline void
|
||||
METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, int basic)
|
||||
{
|
||||
VM_ASSERT(basic <= 1);
|
||||
me->flags = me->flags | (basic << (IMEMO_FL_USHIFT+2));
|
||||
}
|
||||
static inline void
|
||||
METHOD_ENTRY_SAFE_SET(rb_method_entry_t *me, int safe)
|
||||
{
|
||||
VM_ASSERT(safe <= 3);
|
||||
me->flags = (me->flags & ~(IMEMO_FL_USER3 | IMEMO_FL_USER4)) | (safe << IMEMO_FL_USHIFT+3);
|
||||
}
|
||||
static inline void
|
||||
METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, int basic, int safe)
|
||||
{
|
||||
VM_ASSERT(visi <= 3);
|
||||
VM_ASSERT(basic <= 1);
|
||||
VM_ASSERT(safe <= 3);
|
||||
me->flags =
|
||||
(me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2|IMEMO_FL_USER3|IMEMO_FL_USER4)) |
|
||||
((visi << IMEMO_FL_USHIFT+0) | (basic << (IMEMO_FL_USHIFT+2)) | (safe << IMEMO_FL_USHIFT+3));
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
VM_METHOD_TYPE_ISEQ,
|
||||
|
|
14
vm_method.c
14
vm_method.c
|
@ -335,9 +335,7 @@ rb_method_entry_t *
|
|||
rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, rb_method_definition_t *def)
|
||||
{
|
||||
rb_method_entry_t *me = (rb_method_entry_t *)rb_imemo_new(imemo_ment, (VALUE)NULL, (VALUE)called_id, (VALUE)klass, 0);
|
||||
METHOD_ENTRY_VISI(me) = visi;
|
||||
METHOD_ENTRY_BASIC(me) = ruby_running ? FALSE : TRUE;
|
||||
METHOD_ENTRY_SAFE(me) = rb_safe_level();
|
||||
METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE, rb_safe_level());
|
||||
rb_method_definition_reset(me, def);
|
||||
|
||||
VM_ASSERT(def != NULL);
|
||||
|
@ -373,7 +371,7 @@ make_method_entry_refined(rb_method_entry_t *me)
|
|||
|
||||
new_def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id, rb_method_entry_clone(me));
|
||||
rb_method_definition_reset(me, new_def);
|
||||
METHOD_ENTRY_VISI(me) = METHOD_VISI_PUBLIC;
|
||||
METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -561,7 +559,7 @@ method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me,
|
|||
{
|
||||
rb_method_definition_t *def = rb_method_definition_addref(me->def);
|
||||
rb_method_entry_t *newme = rb_method_entry_make(klass, mid, me->def->type, def, visi, defined_class);
|
||||
METHOD_ENTRY_SAFE(newme) = METHOD_ENTRY_SAFE(me);
|
||||
METHOD_ENTRY_SAFE_SET(newme, METHOD_ENTRY_SAFE(me));
|
||||
method_added(klass, mid);
|
||||
return newme;
|
||||
}
|
||||
|
@ -877,10 +875,10 @@ rb_export_method(VALUE klass, ID name, rb_method_visibility_t visi)
|
|||
rb_vm_check_redefinition_opt_method(me, klass);
|
||||
|
||||
if (klass == defined_class || RCLASS_ORIGIN(klass) == defined_class) {
|
||||
METHOD_ENTRY_VISI(me) = visi;
|
||||
METHOD_ENTRY_VISI_SET(me, visi);
|
||||
|
||||
if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) {
|
||||
METHOD_ENTRY_VISI((rb_method_entry_t *)me->def->body.refined.orig_me) = visi;
|
||||
METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi);
|
||||
}
|
||||
rb_clear_method_cache_by_class(klass);
|
||||
}
|
||||
|
@ -1403,7 +1401,7 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
|
|||
RB_OBJ_WRITE(alias_me, &alias_me->klass, defined_class);
|
||||
alias_me->def->original_id = orig_me->called_id;
|
||||
*(ID *)&alias_me->def->body.alias.original_me->called_id = alias_name;
|
||||
METHOD_ENTRY_SAFE(alias_me) = METHOD_ENTRY_SAFE(orig_me);
|
||||
METHOD_ENTRY_SAFE_SET(alias_me, METHOD_ENTRY_SAFE(orig_me));
|
||||
}
|
||||
else {
|
||||
method_entry_set(target_klass, alias_name, orig_me, visi, defined_class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue