Skip to content

container/heap: remove one unnecessary comparison in Fix #16098

@RaduBerinde

Description

@RaduBerinde

The heap.Fix function first calls down and then calls up. If we moved the element down, we don't actually need to call up, saving a comparison (call to Less) in that case. We can do this by having down return whether the element moved and Fix can then do

  if !down(h, i, j.Len()) {
    up(h, i)
  }

This one comparison won't matter in most cases, but if we have only a couple of elements, Less is expensive, and we repeatedly call Fix on the root, it can be significant.

Let me know 1) if it's ok to make this change, and 2) if someone who already has an environment for contributing set up wants to make it (otherwise I will do it).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions