Skip to content

Commit

Permalink
Avoid creating array on every Lexer.all call (#1140)
Browse files Browse the repository at this point in the history
This commit:

- avoids creating a new array on every `Lexer.all` call; and
- flushes the existing list of lexers before registering.
  • Loading branch information
ashmaroli authored and pyrmont committed Jun 3, 2019
1 parent 051f0e9 commit 88a4009
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rouge/lexer.rb
Expand Up @@ -126,7 +126,7 @@ def demo(arg=:absent)

# @return a list of all lexers.
def all
registry.values.uniq
@all ||= registry.values.uniq
end

# Guess which lexer to use based on a hash of info.
Expand Down Expand Up @@ -212,6 +212,8 @@ def detectable?
protected
# @private
def register(name, lexer)
# reset an existing list of lexers
@all = nil if @all
registry[name.to_s] = lexer
end

Expand Down

0 comments on commit 88a4009

Please sign in to comment.