Skip to content

Commit

Permalink
Refactoring of load_path scanning.
Browse files Browse the repository at this point in the history
absolute/relative condition cleanup.
File#isFile() is the bottleneck. It's called iif needed already.
  • Loading branch information
Hiroshi Nakamura committed May 31, 2011
1 parent 17ab324 commit 60d89ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 8 additions & 1 deletion bench/bench_full_load_path.rb
Expand Up @@ -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)
Expand All @@ -32,6 +37,8 @@ def with_loadvars(size)
end
end

gets

Benchmark.bmbm do |bm|
bm.report("empty counterpart") do
with_loadvars(size) do
Expand Down
12 changes: 4 additions & 8 deletions src/org/jruby/runtime/load/LoadService.java
Expand Up @@ -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());
}
Expand Down

0 comments on commit 60d89ba

Please sign in to comment.