Commit 5209c4f4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Improve MetaTagRegistry#tags algorithm.

Build a map by position type once, instead of filtering tags list every time.
parent 21a2f441
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -34,7 +34,17 @@ module JsDuck
    # Returns array of all available tag instances.
    # When position provided, returns only tags in that position
    def tags(position=nil)
      position ? @tags.find_all {|t| t.position == position} : @tags
      return @tags unless position

      unless @position_map
        @position_map = {}
        @tags.each do |t|
          @position_map[t.position] = [] unless @position_map[t.position]
          @position_map[t.position] << t
        end
      end

      @position_map[position] || []
    end

    # Accesses tag by key or name