summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 07:21:37 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 07:21:37 +0000
commitb117572863b63d0cf1aafd89750cf7b51c31304d (patch)
treeda9df15859b791d996f4e179fe47a552a2f6f565
parentb5cd6ba21412b24c5dc44971fe96812e2548cc7e (diff)
* vm.c: eagerly allocate `loading_table`. This eliminates the need to
do NULL checks when looking up the `loading_table` hash. https://github.com/ruby/ruby/pull/918 * load.c: remove various NULL checks git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--load.c99
-rw-r--r--vm.c1
3 files changed, 54 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index 77ebfe1aa7..d655bbdf1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Jun 3 16:17:21 2015 Aaron Patterson <tenderlove@ruby-lang.org>
+
+ * vm.c: eagerly allocate `loading_table`. This eliminates the need to
+ do NULL checks when looking up the `loading_table` hash.
+ https://github.com/ruby/ruby/pull/918
+
+ * load.c: remove various NULL checks
+
Wed Jun 3 11:47:15 2015 Koichi Sasada <ko1@atdot.net>
* method.h: change fileds order to gather frequent acces fields.
diff --git a/load.c b/load.c
index 1d1f51373c..bf1d4ee982 100644
--- a/load.c
+++ b/load.c
@@ -463,56 +463,54 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c
}
loading_tbl = get_loading_table();
- if (loading_tbl) {
- f = 0;
- if (!expanded) {
- struct loaded_feature_searching fs;
- fs.name = feature;
- fs.len = len;
- fs.type = type;
- fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
- fs.result = 0;
- st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
- if ((f = fs.result) != 0) {
- if (fn) *fn = f;
- goto loading;
- }
- }
- if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
- if (fn) *fn = (const char*)data;
- loading:
- if (!ext) return 'u';
- return !IS_RBEXT(ext) ? 's' : 'r';
+ f = 0;
+ if (!expanded) {
+ struct loaded_feature_searching fs;
+ fs.name = feature;
+ fs.len = len;
+ fs.type = type;
+ fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
+ fs.result = 0;
+ st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
+ if ((f = fs.result) != 0) {
+ if (fn) *fn = f;
+ goto loading;
}
- else {
- VALUE bufstr;
- char *buf;
- static const char so_ext[][4] = {
- ".so", ".o",
- };
-
- if (ext && *ext) return 0;
- bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
- buf = RSTRING_PTR(bufstr);
- MEMCPY(buf, feature, char, len);
- for (i = 0; (e = loadable_ext[i]) != 0; i++) {
- strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
- if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
- rb_str_resize(bufstr, 0);
- if (fn) *fn = (const char*)data;
- return i ? 's' : 'r';
- }
+ }
+ if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
+ if (fn) *fn = (const char*)data;
+ loading:
+ if (!ext) return 'u';
+ return !IS_RBEXT(ext) ? 's' : 'r';
+ }
+ else {
+ VALUE bufstr;
+ char *buf;
+ static const char so_ext[][4] = {
+ ".so", ".o",
+ };
+
+ if (ext && *ext) return 0;
+ bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
+ buf = RSTRING_PTR(bufstr);
+ MEMCPY(buf, feature, char, len);
+ for (i = 0; (e = loadable_ext[i]) != 0; i++) {
+ strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
+ if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
+ rb_str_resize(bufstr, 0);
+ if (fn) *fn = (const char*)data;
+ return i ? 's' : 'r';
}
- for (i = 0; i < numberof(so_ext); i++) {
- strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
- if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
- rb_str_resize(bufstr, 0);
- if (fn) *fn = (const char*)data;
- return 's';
- }
+ }
+ for (i = 0; i < numberof(so_ext); i++) {
+ strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
+ if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
+ rb_str_resize(bufstr, 0);
+ if (fn) *fn = (const char*)data;
+ return 's';
}
- rb_str_resize(bufstr, 0);
}
+ rb_str_resize(bufstr, 0);
}
return 0;
}
@@ -716,11 +714,7 @@ load_lock(const char *ftptr)
st_data_t data;
st_table *loading_tbl = get_loading_table();
- if (!loading_tbl || !st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
- /* loading ruby library should be serialized. */
- if (!loading_tbl) {
- GET_VM()->loading_table = loading_tbl = st_init_strtable();
- }
+ if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
/* partial state */
ftptr = ruby_strdup(ftptr);
data = (st_data_t)rb_thread_shield_new();
@@ -1090,9 +1084,6 @@ ruby_init_ext(const char *name, void (*init)(void))
if (rb_provided(name))
return;
- if (!loading_tbl) {
- GET_VM()->loading_table = loading_tbl = st_init_strtable();
- }
st_update(loading_tbl, (st_data_t)name, register_init_ext, (st_data_t)init);
}
diff --git a/vm.c b/vm.c
index 6b3f4fec13..0702e8a39e 100644
--- a/vm.c
+++ b/vm.c
@@ -2859,6 +2859,7 @@ Init_vm_objects(void)
/* initialize mark object array, hash */
vm->mark_object_ary = rb_ary_tmp_new(128);
+ vm->loading_table = st_init_strtable();
}
/* top self */