Skip to content

Commit

Permalink
thread.c: id locals
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed May 2, 2013
1 parent 97982e8 commit 3145777
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Thu May 2 16:54:07 2013 Nobuyoshi Nakada <[email protected]>
Thu May 2 16:55:43 2013 Nobuyoshi Nakada <[email protected]>

* thread.c (id_locals): use cached ID.

* vm.c (ruby_thread_init): ditto.

* defs/id.def: add more predefined IDs used in core.

Expand Down
10 changes: 6 additions & 4 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3145777

Please sign in to comment.