diff --git a/CHANGELOG.md b/CHANGELOG.md index 44953bc..5f97ac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Update our CI matrix to include recent versions of Prawn and Ruby! Thanks @petergoldstein! (#55) * Resolve a few code smells that were flagged by Rubocop. * [Material Design Icons](https://materialdesignicons.com) are now supported! Currently version `7.0.96` is included. Thanks @maneex! [https://github.com/jessedoyle/prawn-icon/pull/59](Pull Request). +* Memoize calls to `Prawn::Icon::FontData#path` to improve performance. #### Material Design Icons diff --git a/README.md b/README.md index 0dfb38c..5fd8c29 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Prawn::Icon provides a simple mechanism for rendering icons and icon fonts from The following icon fonts ship with Prawn::Icon: * FontAwesome (http://fontawesome.io/icons/) +* Material Design Icons (https://materialdesignicons.com/) * Foundation Icons (http://zurb.com/playground/foundation-icon-fonts-3) * PaymentFont (https://paymentfont.com) diff --git a/lib/prawn/icon/font_data.rb b/lib/prawn/icon/font_data.rb index 6669b1b..c36e74d 100644 --- a/lib/prawn/icon/font_data.rb +++ b/lib/prawn/icon/font_data.rb @@ -63,17 +63,19 @@ def load_fonts(document) end def path - font = Icon.configuration.font_directory - .join(@set.to_s) - .glob('*.ttf') - .first - - if font.nil? - raise Prawn::Errors::UnknownFont, - "Icon font not found for set: #{@set}" - end + @path = begin + font = Icon.configuration.font_directory + .join(@set.to_s) + .glob('*.ttf') + .first + + if font.nil? + raise Prawn::Errors::UnknownFont, + "Icon font not found for set: #{@set}" + end - @path ||= font.to_s + font.to_s + end end def specifier