discourse / mini_mime

minimal mime type library
MIT License
95 stars 34 forks source link

Adjusting lookup_by_filename on performance & style #10

Closed esparta closed 6 years ago

esparta commented 6 years ago

Having the fact that File.extname returns an empty string on the edge cases (no extension, '.', not-valid-paths, etc), we can remove a superflous if statement and replace the inner else with a single guard.

This improve the performance up to 10% on cached and non_cached values Also, we can reduce the allocated memory:

Before: 56689 bytes (376 objects) After: 56291 bytes (371 objects) Diff: 398 bytes ( 5 objects)

SamSaffron commented 6 years ago

nice change! code is clearer as well