Skip to content

Commit

Permalink
Simplify logic for finding the most specific load path for absolute p…
Browse files Browse the repository at this point in the history
…aths

Simplified the implementation for determining the load path that contains an absolute path feature by replacing the relative path size comparison with a direct check of the longest matching path. This change removes unnecessary relative path calculations, leveraging the fact that subpath? already ensures a match, thus making the code more efficient and easier to understand.
  • Loading branch information
shinokaro committed Jul 9, 2024
1 parent fe709f4 commit d5526cc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ module Ocran
def self.find_load_path(load_paths, path)
if path.absolute?
# For an absolute path feature, find the load path that contains the feature
# and determine the shortest possible require-path (most specific path).
# and determine the longest matching path (most specific path).
load_paths.select { |load_path| path.subpath?(File.expand_path(load_path)) }
.min_by { |load_path| path.relative_path_from(File.expand_path(load_path)).to_s.size }
.max_by { |load_path| File.expand_path(load_path).length }
else
# For a relative path feature, find the load path where the expanded feature exists
# and select the longest load path (most specific path).
Expand Down

0 comments on commit d5526cc

Please sign in to comment.