Skip to content
Browse files

Don't needlessly create a new string in rb_feature_provided.

  • Loading branch information...
1 parent 4b6040b commit 49beb2037a7e93132172a5d498efa2f76aada7b0 @xaviershay committed May 20, 2011
Showing with 14 additions and 8 deletions.
  1. +11 −4 load.c
  2. +3 −4 variable.c
View
15 load.c
@@ -819,15 +819,22 @@ rb_file_is_being_required(VALUE full_path) {
return (loading_tbl && st_lookup(loading_tbl, (st_data_t)ftptr, &data));
}
-/* Should return true if the file has or is being loaded, but should
- * not actually load the file.
+/*
+ * Deprecated, use rb_feature_provided_2
*/
int
rb_feature_provided(const char *feature, const char **loading)
{
- // TODO: feature is converted to a char* just to pass into
- // this function, which is kind of redundant
VALUE fname = rb_str_new2(feature);
+ rb_feature_provided_2(fname);
+}
+
+/* Should return true if the file has or is being loaded, but should
+ * not actually load the file.
+ */
+int
+rb_feature_provided_2(VALUE fname)
+{
VALUE full_path = rb_locate_file(fname);
if (rb_file_has_been_required(full_path) || rb_file_is_being_required(full_path)) {
View
7 variable.c
@@ -1488,10 +1488,9 @@ autoload_delete(VALUE mod, ID id)
}
static VALUE
-autoload_provided(VALUE arg)
+autoload_provided(VALUE fname)
{
- const char **p = (const char **)arg;
- return rb_feature_provided(*p, p);
+ return rb_feature_provided_2(fname);
}
static VALUE
@@ -1524,7 +1523,7 @@ autoload_node(VALUE mod, ID id, const char **loadingpath)
loading = RSTRING_PTR(file);
safe = rb_safe_level();
rb_set_safe_level_force(0);
- if (!rb_ensure(autoload_provided, (VALUE)&loading, reset_safe, (VALUE)safe)) {
+ if (!rb_ensure(autoload_provided, (VALUE)file, reset_safe, (VALUE)safe)) {
return load;
}
if (loadingpath && loading) {

0 comments on commit 49beb20

Please sign in to comment.
Something went wrong with that request. Please try again.