File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed
Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -197,20 +197,16 @@ fn read_entry<R: Read>(r: &mut R) -> ImageResult<DirEntry> {
197197/// do exist. Since we can't make an educated guess which one is best, picking
198198/// the first one is a reasonable default.
199199fn best_entry ( entries : Vec < DirEntry > ) -> ImageResult < DirEntry > {
200- let mut best = * entries. first ( ) . ok_or ( DecoderError :: NoEntries ) ?;
201- let mut best_score = ( 0 , 0 ) ;
202-
203- for entry in entries {
204- let score = (
205- entry. bits_per_pixel ,
206- u32:: from ( entry. real_width ( ) ) * u32:: from ( entry. real_height ( ) ) ,
207- ) ;
208- if score > best_score {
209- best = entry;
210- best_score = score;
211- }
212- }
213- Ok ( best)
200+ entries
201+ . into_iter ( )
202+ . rev ( ) // ties should pick the first entry, not the last
203+ . max_by_key ( |entry| {
204+ (
205+ entry. bits_per_pixel ,
206+ u32:: from ( entry. real_width ( ) ) * u32:: from ( entry. real_height ( ) ) ,
207+ )
208+ } )
209+ . ok_or ( DecoderError :: NoEntries . into ( ) )
214210}
215211
216212impl DirEntry {
You can’t perform that action at this time.
0 commit comments