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

Fix infinite loop bug #1786

Open
wants to merge 5 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Rarity Map Performance fix

Do not calculate the rarest piece unless it is needed.
It is an expensive operation.
  • Loading branch information
koush committed Jan 2, 2020
commit f5d22c45db0c3c06d1d26288b67b66890134cb31
@@ -10,21 +10,21 @@ class RarityMap {
this._pieces = new Array(this._numPieces)

this._onWire = wire => {
this.recalculate()
this._dirty = true
this._initWire(wire)
}
this._onWireHave = index => {
this._pieces[index] += 1
}
this._onWireBitfield = () => {
this.recalculate()
this._dirty = true
}

this._torrent.wires.forEach(wire => {
this._initWire(wire)
})
this._torrent.on('wire', this._onWire)
this.recalculate()
this._dirty = true
}

/**
@@ -35,6 +35,11 @@ class RarityMap {
* @return {number} index of rarest piece, or -1
*/
getRarestPiece (pieceFilterFunc) {
if (this._dirty) {
this._dirty = false
this.recalculate()
}

let candidates = []
let min = Infinity

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.