Skip to content

Commit

Permalink
Merge pull request #60 from jessedoyle/optimize/cache-calls
Browse files Browse the repository at this point in the history
optimize(fonts): Memoize Font Path
  • Loading branch information
jessedoyle authored Sep 2, 2022
2 parents 672499b + 1d0c99b commit e76a293
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 12 additions & 10 deletions lib/prawn/icon/font_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e76a293

Please sign in to comment.