@@ -50,29 +50,37 @@ def self.library_paths(conf_path = Pathname(sysconfdir)/"ld.so.conf")
50
50
conf_file = Pathname ( conf_path )
51
51
return [ ] unless conf_file . exist?
52
52
53
+ @library_paths_cache ||= T . let ( { } , T . nilable ( T ::Hash [ String , T ::Array [ String ] ] ) )
54
+ cache_key = conf_file . to_s
55
+ if ( cached_library_path_contents = @library_paths_cache [ cache_key ] )
56
+ return cached_library_path_contents
57
+ end
58
+
53
59
paths = Set . new
54
60
directory = conf_file . realpath . dirname
55
61
56
- conf_file . readlines . each do |line |
57
- # Remove comments and leading/trailing whitespace
58
- line . strip!
59
- line . sub! ( /\s *#.*$/ , "" )
60
-
61
- if line . start_with? ( /\s *include\s +/ )
62
- include_path = Pathname ( line . sub ( /^\s *include\s +/ , "" ) ) . expand_path
63
- wildcard = include_path . absolute? ? include_path : directory /include_path
64
-
65
- Dir . glob ( wildcard . to_s ) . each do |include_file |
66
- paths += library_paths ( include_file )
62
+ conf_file . open ( "r" ) do |file |
63
+ file . each_line do |line |
64
+ # Remove comments and leading/trailing whitespace
65
+ line . strip!
66
+ line . sub! ( /\s *#.*$/ , "" )
67
+
68
+ if line . start_with? ( /\s *include\s +/ )
69
+ include_path = Pathname ( line . sub ( /^\s *include\s +/ , "" ) ) . expand_path
70
+ wildcard = include_path . absolute? ? include_path : directory /include_path
71
+
72
+ Dir . glob ( wildcard . to_s ) . each do |include_file |
73
+ paths += library_paths ( include_file )
74
+ end
75
+ elsif line . empty?
76
+ next
77
+ else
78
+ paths << line
67
79
end
68
- elsif line . empty?
69
- next
70
- else
71
- paths << line
72
80
end
73
81
end
74
82
75
- paths . to_a
83
+ @library_paths_cache [ cache_key ] = paths . to_a
76
84
end
77
85
end
78
86
end
0 commit comments