Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RaduBerinde opened this issue Jun 17, 2016 · 2 comments
Closed

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

RaduBerinde opened this issue Jun 17, 2016 · 2 comments

Comments

@RaduBerinde
Copy link
Contributor

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).

@griesemer
Copy link
Contributor

@RaduBerinde Seems reasonable. I've assigned it to me, but feel free to send a CL if you like. This is not urgent.

@griesemer griesemer self-assigned this Jun 17, 2016
@griesemer griesemer added this to the Unplanned milestone Jun 17, 2016
@gopherbot
Copy link

CL https://golang.org/cl/24273 mentions this issue.

@golang golang locked and limited conversation to collaborators Aug 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants