Permalink
Browse files

Refactoring of load_path scanning.

absolute/relative condition cleanup.
File#isFile() is the bottleneck. It's called iif needed already.
  • Loading branch information...
1 parent 17ab324 commit 60d89ba95154e84d6af392f3d6ca40ca920146a5 @nahi nahi committed May 31, 2011
Showing with 12 additions and 9 deletions.
  1. +8 −1 bench/bench_full_load_path.rb
  2. +4 −8 src/org/jruby/runtime/load/LoadService.java
@@ -5,7 +5,12 @@
target_size = (ARGV.shift || '10000').to_i # must be bigger than 50
require_size = 50
-TEST_DIR = File.expand_path('full_load_path_test', File.dirname(__FILE__))
+# for testing with abloute path
+#TEST_DIR = File.expand_path('full_load_path_test', File.dirname(__FILE__))
+
+# for testing with relative path
+Dir.chdir File.dirname(__FILE__)
+TEST_DIR = 'full_load_path_test'
unless File.directory?(TEST_DIR)
FileUtils.mkdir(TEST_DIR)
@@ -32,6 +37,8 @@ def with_loadvars(size)
end
end
+gets
+
Benchmark.bmbm do |bm|
bm.report("empty counterpart") do
with_loadvars(size) do
@@ -1155,21 +1155,17 @@ protected LoadServiceResource tryResourceFromLoadPath( String namePlusSuffix,Str
try {
if (!Ruby.isSecurityRestricted()) {
String reportedPath = loadPathEntry + "/" + namePlusSuffix;
- JRubyFile actualPath;
- boolean absolute = false;
+ boolean absolute = true;
// we check length == 0 for 'load', which does not use load path
- if (new File(reportedPath).isAbsolute()) {
- absolute = true;
- // it's an absolute path, use it as-is
- actualPath = JRubyFile.create(loadPathEntry, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
- } else {
+ if (!new File(reportedPath).isAbsolute()) {
absolute = false;
// prepend ./ if . is not already there, since we're loading based on CWD
if (reportedPath.charAt(0) != '.') {
reportedPath = "./" + reportedPath;
}
- actualPath = JRubyFile.create(JRubyFile.create(runtime.getCurrentDirectory(), loadPathEntry).getAbsolutePath(), RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
+ loadPathEntry = JRubyFile.create(runtime.getCurrentDirectory(), loadPathEntry).getAbsolutePath();
}
+ JRubyFile actualPath = JRubyFile.create(loadPathEntry, RubyFile.expandUserPath(runtime.getCurrentContext(), namePlusSuffix));
if (RubyInstanceConfig.DEBUG_LOAD_SERVICE) {
debugLogTry("resourceFromLoadPath", "'" + actualPath.toString() + "' " + actualPath.isFile() + " " + actualPath.canRead());
}

0 comments on commit 60d89ba

Please sign in to comment.