    # File lib/rubygems/source_index.rb, line 138
      def latest_specs
        result = Hash.new { |h,k| h[k] = [] }
        latest = {}

        sort.each do |_, spec|
          name = spec.name
          curr_ver = spec.version
          prev_ver = latest.key?(name) ? latest[name].version : nil

          next unless prev_ver.nil? or curr_ver >= prev_ver or
                      latest[name].platform != Gem::Platform::RUBY

          if prev_ver.nil? or
             (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
            result[name].clear
            latest[name] = spec
          end

          if spec.platform != Gem::Platform::RUBY then
            result[name].delete_if do |result_spec|
              result_spec.platform == spec.platform
            end
          end

          result[name] << spec
        end

        result.values.flatten
      end