summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 07:21:37 (GMT)
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-03 07:21:37 (GMT)
commitb117572863b63d0cf1aafd89750cf7b51c31304d (patch)
treeda9df15859b791d996f4e179fe47a552a2f6f565 /load.c
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
Diffstat (limited to 'load.c')
-rw-r--r--load.c99
1 files changed, 45 insertions, 54 deletions
diff --git a/load.c b/load.c
index 1d1f513..bf1d4ee 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);
}