180 |
180 |
return GET_VM()->loading_table;
|
181 |
181 |
}
|
182 |
182 |
|
|
183 |
static st_data_t
|
|
184 |
feature_key(const char *str, size_t len)
|
|
185 |
{
|
|
186 |
return st_hash(str, len, 0xfea7009e);
|
|
187 |
}
|
|
188 |
|
183 |
189 |
static void
|
184 |
|
features_index_add_single(VALUE short_feature, VALUE offset)
|
|
190 |
features_index_add_single(const char* str, size_t len, VALUE offset)
|
185 |
191 |
{
|
186 |
192 |
struct st_table *features_index;
|
187 |
193 |
VALUE this_feature_index = Qnil;
|
188 |
|
char *short_feature_cstr;
|
|
194 |
st_data_t short_feature_key;
|
189 |
195 |
|
190 |
196 |
Check_Type(offset, T_FIXNUM);
|
191 |
|
Check_Type(short_feature, T_STRING);
|
192 |
|
short_feature_cstr = StringValueCStr(short_feature);
|
|
197 |
short_feature_key = feature_key(str, len);
|
193 |
198 |
|
194 |
199 |
features_index = get_loaded_features_index_raw();
|
195 |
|
st_lookup(features_index, (st_data_t)short_feature_cstr, (st_data_t *)&this_feature_index);
|
|
200 |
st_lookup(features_index, short_feature_key, (st_data_t *)&this_feature_index);
|
196 |
201 |
|
197 |
202 |
if (NIL_P(this_feature_index)) {
|
198 |
|
st_insert(features_index, (st_data_t)ruby_strdup(short_feature_cstr), (st_data_t)offset);
|
|
203 |
st_insert(features_index, short_feature_key, (st_data_t)offset);
|
199 |
204 |
}
|
200 |
205 |
else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
|
201 |
206 |
VALUE feature_indexes[2];
|
... | ... | |
204 |
209 |
this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
|
205 |
210 |
RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
|
206 |
211 |
rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
|
207 |
|
st_insert(features_index, (st_data_t)short_feature_cstr, (st_data_t)this_feature_index);
|
|
212 |
st_insert(features_index, short_feature_key, (st_data_t)this_feature_index);
|
208 |
213 |
}
|
209 |
214 |
else {
|
210 |
215 |
Check_Type(this_feature_index, T_ARRAY);
|
... | ... | |
223 |
228 |
static void
|
224 |
229 |
features_index_add(VALUE feature, VALUE offset)
|
225 |
230 |
{
|
226 |
|
VALUE short_feature;
|
227 |
231 |
const char *feature_str, *feature_end, *ext, *p;
|
228 |
232 |
|
229 |
233 |
feature_str = StringValuePtr(feature);
|
... | ... | |
239 |
243 |
|
240 |
244 |
p = ext ? ext : feature_end;
|
241 |
245 |
while (1) {
|
242 |
|
long beg;
|
243 |
|
|
244 |
246 |
p--;
|
245 |
247 |
while (p >= feature_str && *p != '/')
|
246 |
248 |
p--;
|
247 |
249 |
if (p < feature_str)
|
248 |
250 |
break;
|
249 |
251 |
/* Now *p == '/'. We reach this point for every '/' in `feature`. */
|
250 |
|
beg = p + 1 - feature_str;
|
251 |
|
short_feature = rb_str_subseq(feature, beg, feature_end - p - 1);
|
252 |
|
features_index_add_single(short_feature, offset);
|
|
252 |
features_index_add_single(p + 1, feature_end - p - 1, offset);
|
253 |
253 |
if (ext) {
|
254 |
|
short_feature = rb_str_subseq(feature, beg, ext - p - 1);
|
255 |
|
features_index_add_single(short_feature, offset);
|
|
254 |
features_index_add_single(p + 1, ext - p - 1, offset);
|
256 |
255 |
}
|
257 |
256 |
}
|
258 |
|
features_index_add_single(feature, offset);
|
|
257 |
features_index_add_single(feature_str, feature_end - feature_str, offset);
|
259 |
258 |
if (ext) {
|
260 |
|
short_feature = rb_str_subseq(feature, 0, ext - feature_str);
|
261 |
|
features_index_add_single(short_feature, offset);
|
|
259 |
features_index_add_single(feature_str, ext - feature_str, offset);
|
262 |
260 |
}
|
263 |
261 |
}
|
264 |
262 |
|
... | ... | |
270 |
268 |
rb_ary_free(obj);
|
271 |
269 |
xfree((void *)obj);
|
272 |
270 |
}
|
273 |
|
xfree((char *)key);
|
274 |
271 |
return ST_DELETE;
|
275 |
272 |
}
|
276 |
273 |
|
... | ... | |
383 |
380 |
long i, len, elen, n;
|
384 |
381 |
st_table *loading_tbl, *features_index;
|
385 |
382 |
st_data_t data;
|
|
383 |
st_data_t key;
|
386 |
384 |
int type;
|
387 |
385 |
|
388 |
386 |
if (fn) *fn = 0;
|
... | ... | |
399 |
397 |
features = get_loaded_features();
|
400 |
398 |
features_index = get_loaded_features_index();
|
401 |
399 |
|
402 |
|
st_lookup(features_index, (st_data_t)feature, (st_data_t *)&this_feature_index);
|
|
400 |
key = feature_key(feature, strlen(feature));
|
|
401 |
st_lookup(features_index, key, (st_data_t *)&this_feature_index);
|
403 |
402 |
/* We search `features` for an entry such that either
|
404 |
403 |
"#{features[i]}" == "#{load_path[j]}/#{feature}#{e}"
|
405 |
404 |
for some j, or
|
... | ... | |
1196 |
1195 |
rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0);
|
1197 |
1196 |
vm->loaded_features = rb_ary_new();
|
1198 |
1197 |
vm->loaded_features_snapshot = rb_ary_tmp_new(0);
|
1199 |
|
vm->loaded_features_index = st_init_strtable();
|
|
1198 |
vm->loaded_features_index = st_init_numtable();
|
1200 |
1199 |
|
1201 |
1200 |
rb_define_global_function("load", rb_f_load, -1);
|
1202 |
1201 |
rb_define_global_function("require", rb_f_require, 1);
|
1203 |
|
-
|