1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
tenderlove 2015-06-03 07:21:37 +00:00
parent b5cd6ba214
commit b117572863
3 changed files with 54 additions and 54 deletions

View file

@ -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.

99
load.c
View file

@ -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;
}
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';
}
else {
VALUE bufstr;
char *buf;
static const char so_ext[][4] = {
".so", ".o",
};
}
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';
}
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';
}
}
rb_str_resize(bufstr, 0);
}
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);
}
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);
}

1
vm.c
View file

@ -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 */