mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c: id locals
* thread.c (id_locals): use cached ID. * vm.c (ruby_thread_init): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
97982e823f
commit
31457774a8
3 changed files with 12 additions and 6 deletions
|
@ -1,4 +1,8 @@
|
|||
Thu May 2 16:54:07 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Thu May 2 16:55:43 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* thread.c (id_locals): use cached ID.
|
||||
|
||||
* vm.c (ruby_thread_init): ditto.
|
||||
|
||||
* defs/id.def: add more predefined IDs used in core.
|
||||
|
||||
|
|
10
thread.c
10
thread.c
|
@ -80,6 +80,7 @@ VALUE rb_cThreadShield;
|
|||
static VALUE sym_immediate;
|
||||
static VALUE sym_on_blocking;
|
||||
static VALUE sym_never;
|
||||
static ID id_locals;
|
||||
|
||||
static void sleep_timeval(rb_thread_t *th, struct timeval time, int spurious_check);
|
||||
static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check);
|
||||
|
@ -2898,7 +2899,7 @@ rb_thread_variable_get(VALUE thread, VALUE key)
|
|||
}
|
||||
|
||||
if (!id) return Qnil;
|
||||
locals = rb_iv_get(thread, "locals");
|
||||
locals = rb_ivar_get(thread, id_locals);
|
||||
return rb_hash_aref(locals, ID2SYM(id));
|
||||
}
|
||||
|
||||
|
@ -2926,7 +2927,7 @@ rb_thread_variable_set(VALUE thread, VALUE id, VALUE val)
|
|||
rb_error_frozen("thread locals");
|
||||
}
|
||||
|
||||
locals = rb_iv_get(thread, "locals");
|
||||
locals = rb_ivar_get(thread, id_locals);
|
||||
return rb_hash_aset(locals, ID2SYM(rb_to_id(id)), val);
|
||||
}
|
||||
|
||||
|
@ -3041,7 +3042,7 @@ rb_thread_variables(VALUE thread)
|
|||
VALUE locals;
|
||||
VALUE ary;
|
||||
|
||||
locals = rb_iv_get(thread, "locals");
|
||||
locals = rb_ivar_get(thread, id_locals);
|
||||
ary = rb_ary_new();
|
||||
rb_hash_foreach(locals, keys_i, ary);
|
||||
|
||||
|
@ -3072,7 +3073,7 @@ rb_thread_variable_p(VALUE thread, VALUE key)
|
|||
|
||||
if (!id) return Qfalse;
|
||||
|
||||
locals = rb_iv_get(thread, "locals");
|
||||
locals = rb_ivar_get(thread, id_locals);
|
||||
|
||||
if (!RHASH(locals)->ntbl)
|
||||
return Qfalse;
|
||||
|
@ -5013,6 +5014,7 @@ Init_Thread(void)
|
|||
sym_never = ID2SYM(rb_intern("never"));
|
||||
sym_immediate = ID2SYM(rb_intern("immediate"));
|
||||
sym_on_blocking = ID2SYM(rb_intern("on_blocking"));
|
||||
id_locals = rb_intern("locals");
|
||||
|
||||
rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1);
|
||||
rb_define_singleton_method(rb_cThread, "start", thread_start, -2);
|
||||
|
|
2
vm.c
2
vm.c
|
@ -1988,7 +1988,7 @@ ruby_thread_init(VALUE self)
|
|||
|
||||
th->vm = vm;
|
||||
th_init(th, self);
|
||||
rb_iv_set(self, "locals", rb_hash_new());
|
||||
rb_ivar_set(self, rb_intern("locals"), rb_hash_new());
|
||||
|
||||
th->top_wrapper = 0;
|
||||
th->top_self = rb_vm_top_self();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue