Skip to content

Commit

Permalink
move directory test to earlier for faster fuzzy finder
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Feb 16, 2010
1 parent 7456c66 commit afeafe9
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions plugins/project/lib/project/find_file_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def files(directories)
took = Time.now - s
puts "find files #{directories.length} took #{took}s"
files
files.reject!{|f|
begin
File.directory?(f)
rescue Errno::ENOENT
# File.directory? can throw no such file or directory even if File.exist?
# has returned true. For example this happens on some awful textmate filenames
# unicode in them.
true
end
}
files
end
end

Expand All @@ -88,26 +99,24 @@ def find_files(text, directories)
cutoff = 10000000
results = files(directories).each do |fn|
begin
unless File.directory?(fn)
bit = fn.split("/")
if m = bit.last.match(re)
cs = []
diffs = 0
m.captures.each_with_index do |_, i|
cs << m.begin(i + 1)
if i > 0
diffs += cs[i] - cs[i-1]
end
bit = fn.split("/")
if m = bit.last.match(re)
cs = []
diffs = 0
m.captures.each_with_index do |_, i|
cs << m.begin(i + 1)
if i > 0
diffs += cs[i] - cs[i-1]
end
# lower score is better
score = (cs[0] + diffs)*100 + bit.last.length
if score < cutoff
score_match_pairs << [score, fn]
score_match_pairs.sort!
if score_match_pairs.length == MAX_ENTRIES
cutoff = score_match_pairs.last.first
score_match_pairs.pop
end
end
# lower score is better
score = (cs[0] + diffs)*100 + bit.last.length
if score < cutoff
score_match_pairs << [score, fn]
score_match_pairs.sort!
if score_match_pairs.length == MAX_ENTRIES
cutoff = score_match_pairs.last.first
score_match_pairs.pop
end
end
end
Expand Down

0 comments on commit afeafe9

Please sign in to comment.