@@ -6,8 +6,6 @@ module Private
6
6
class GlobCache
7
7
extend T ::Sig
8
8
9
- EXPANDED_CACHE_FILE_COUNT_THRESHOLD = 100
10
-
11
9
MapperDescription = T . type_alias { String }
12
10
13
11
CacheShape = T . type_alias do
@@ -36,19 +34,15 @@ def raw_cache_contents
36
34
37
35
sig { params ( files : T ::Array [ String ] ) . returns ( FilesByMapper ) }
38
36
def mapper_descriptions_that_map_files ( files )
39
- if files . count > EXPANDED_CACHE_FILE_COUNT_THRESHOLD
40
- # When looking at many files, expanding the cache out using Dir.glob and checking for intersections is faster
41
- files_by_mappers = files . to_h { |f | [ f , Set . new ( [ ] ) ] }
37
+ files_by_mappers = files . to_h { |f | [ f , Set . new ( [ ] ) ] }
42
38
43
- files_by_mappers_via_expanded_cache . each do |file , mapper |
39
+ files_by_mappers_via_expanded_cache . each do |file , mappers |
40
+ mappers . each do |mapper |
44
41
T . must ( files_by_mappers [ file ] ) << mapper if files_by_mappers [ file ]
45
42
end
46
-
47
- files_by_mappers
48
- else
49
- # When looking at few files, using File.fnmatch is faster
50
- files_by_mappers_via_file_fnmatch ( files )
51
43
end
44
+
45
+ files_by_mappers
52
46
end
53
47
54
48
private
@@ -81,31 +75,6 @@ def files_by_mappers_via_expanded_cache
81
75
files_by_mappers
82
76
end
83
77
end
84
-
85
- sig { params ( files : T ::Array [ String ] ) . returns ( FilesByMapper ) }
86
- def files_by_mappers_via_file_fnmatch ( files )
87
- files_by_mappers = T . let ( { } , FilesByMapper )
88
-
89
- files . each do |file |
90
- files_by_mappers [ file ] ||= Set . new ( [ ] )
91
- @raw_cache_contents . each do |mapper_description , globs_by_owner |
92
- # As much as I'd like to *not* special case the file annotations mapper, using File.fnmatch? on the thousands of files mapped by the
93
- # file annotations mapper is a lot of unnecessary extra work.
94
- # Therefore we can just check if the file is in the globs directly for file annotations, otherwise use File.fnmatch
95
- if mapper_description == OwnershipMappers ::FileAnnotations ::DESCRIPTION
96
- files_by_mappers . fetch ( file ) << mapper_description if globs_by_owner [ file ]
97
- else
98
- globs_by_owner . each_key do |glob |
99
- if File . fnmatch? ( glob , file , File ::FNM_PATHNAME | File ::FNM_EXTGLOB )
100
- files_by_mappers . fetch ( file ) << mapper_description
101
- end
102
- end
103
- end
104
- end
105
- end
106
-
107
- files_by_mappers
108
- end
109
78
end
110
79
end
111
80
end
0 commit comments