aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-11 04:12:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-11 04:12:56 +0000
commita6f7aa17c8c99e45e1b79064c458db6b61fcbe4b (patch)
treece7ca1f3e006d3824cb93c72b0842162f9c0effd /variable.c
parentcd463d1551bbacae2d1cc60c729f7d2121b4bbc0 (diff)
downloadruby-a6f7aa17c8c99e45e1b79064c458db6b61fcbe4b.tar.gz
variable.c: fix the condition to cache
* variable.c (rb_const_set): fix the condition to cache the class path and cache permanent or temporary path corresponding to the outer klass. [ruby-core:79039] [Bug #13120] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/variable.c b/variable.c
index 98b9073a02..c69764f18d 100644
--- a/variable.c
+++ b/variable.c
@@ -2612,10 +2612,25 @@ rb_const_set(VALUE klass, ID id, VALUE val)
* and avoid order-dependency on const_tbl
*/
if (rb_cObject && (RB_TYPE_P(val, T_MODULE) || RB_TYPE_P(val, T_CLASS))) {
- if (!NIL_P(rb_class_path_cached(val))) {
- rb_name_class(val, id);
- if (rb_class_path_cached(klass)) {
- rb_class_name(val);
+ if (NIL_P(rb_class_path_cached(val))) {
+ if (klass == rb_cObject) {
+ rb_ivar_set(val, classpath, rb_id2str(id));
+ rb_name_class(val, id);
+ }
+ else {
+ VALUE path;
+ ID pathid;
+ st_data_t n;
+ st_table *ivtbl = RCLASS_IV_TBL(klass);
+ if (ivtbl &&
+ (st_lookup(ivtbl, (st_data_t)(pathid = classpath), &n) ||
+ st_lookup(ivtbl, (st_data_t)(pathid = tmp_classpath), &n))) {
+ path = rb_str_dup((VALUE)n);
+ rb_str_append(rb_str_cat2(path, "::"), rb_id2str(id));
+ OBJ_FREEZE(path);
+ rb_ivar_set(val, pathid, path);
+ rb_name_class(val, id);
+ }
}
}
}