Skip to content

Commit

Permalink
Fixes #1936
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Sep 2, 2014
1 parent da593bf commit 8c31952
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions core/src/main/java/org/jruby/runtime/load/LibrarySearcher.java
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;

import org.jruby.Ruby;
import org.jruby.RubyFile;
import org.jruby.RubyHash;
import org.jruby.RubyString;
import org.jruby.ast.executable.Script;
Expand Down Expand Up @@ -139,17 +140,26 @@ private FoundLibrary findResourceLibrary(String baseName, String suffix) {
return findFileResource(baseName, suffix);
}

for (IRubyObject loadPathEntry : loadService.loadPath.toJavaArray()) {
String loadPathString = loadPathEntry.convertToString().asJavaString();
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, loadPathString);
if (library != null) {
return library;
try {
for (IRubyObject loadPathEntry : loadService.loadPath.toJavaArray()) {
FoundLibrary library = findFileResourceWithLoadPath(baseName, suffix, getPath(loadPathEntry));
if (library != null) return library;
}
} catch (Throwable t) {
t.printStackTrace();
}

return null;
}

// FIXME: to_path should not be called n times it should only be once and that means a cache which would
// also reduce all this casting and/or string creates.
private String getPath(IRubyObject loadPathEntry) {
if (runtime.is1_8()) return loadPathEntry.convertToString().asJavaString();

return RubyFile.get_path(runtime.getCurrentContext(), loadPathEntry).asJavaString();
}

private FoundLibrary findFileResource(String searchName, String suffix) {
return findFileResourceWithLoadPath(searchName, suffix, null);
}
Expand Down

0 comments on commit 8c31952

Please sign in to comment.