<commit_before>class CompositionRow
  attr_reader :player, :number

  def initialize(number:, player:, builder:)
    @number = number
    @player = player
    @builder = builder
  end

  def heroes
    if player
      player.heroes_by_confidence(@builder.heroes)
    else
      @builder.heroes
    end
  end

  def selected_hero(map_segment)
    return unless player

    selection = @builder.player_selections.detect do |ps|
      ps.map_segment_id == map_segment.id &&
        ps.position == number && ps.player_id == player.id
    end
    selection ? selection.hero_id : nil
  end
end<commit_msg>Memoize #selected_hero by map segment<commit_after>class CompositionRow
  attr_reader :player, :number

  def initialize(number:, player:, builder:)
    @number = number
    @player = player
    @builder = builder
    @heroes_by_segment = {}
  end

  def heroes
    if player
      player.heroes_by_confidence(@builder.heroes)
    else
      @builder.heroes
    end
  end

  def selected_hero(map_segment)
    if @heroes_by_segment.key?(map_segment.id)
      return @heroes_by_segment[map_segment.id]
    end

    unless player
      @heroes_by_segment[map_segment.id] = nil
      return
    end

    selection = @builder.player_selections.detect do |ps|
      ps.map_segment_id == map_segment.id &&
        ps.position == number && ps.player_id == player.id
    end
    @heroes_by_segment[map_segment.id] = selection ? selection.hero_id : nil
  end
end
{'fraction_non_alphanumeric': 0.08884297520661157, 'fraction_numerical': 0.0, 'mean_word_length': 3.0249307479224377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7364574', 'n_tokens_mistral': 473, 'n_tokens_neox': 460, 'n_words': 105}