@@ -6,8 +6,6 @@ module Private
66 class GlobCache
77 extend T ::Sig
88
9- EXPANDED_CACHE_FILE_COUNT_THRESHOLD = 100
10-
119 MapperDescription = T . type_alias { String }
1210
1311 CacheShape = T . type_alias do
@@ -36,19 +34,15 @@ def raw_cache_contents
3634
3735 sig { params ( files : T ::Array [ String ] ) . returns ( FilesByMapper ) }
3836 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 ( [ ] ) ] }
4238
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 |
4441 T . must ( files_by_mappers [ file ] ) << mapper if files_by_mappers [ file ]
4542 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 )
5143 end
44+
45+ files_by_mappers
5246 end
5347
5448 private
@@ -81,31 +75,6 @@ def files_by_mappers_via_expanded_cache
8175 files_by_mappers
8276 end
8377 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
10978 end
11079 end
11180end
0 commit comments