Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upmodernize lib/rarity-map.js #1485
Merged
+85
−98
Conversation
lib/rarity-map.js
Outdated
| self._pieces = [] | ||
| self._torrent = torrent | ||
| self._numPieces = torrent.pieces.length | ||
| self._pieces = new Array(self._numPieces).fill(0) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jimmywarting
Aug 26, 2018
Author
Contributor
You probably don't need the initial .fill(0) in new Array(self._numPieces).fill(0) maybe just new Array(self._numPieces) will do
Reason why i did this was b/c new Array(n) is faster then writing to a literal array []
And using .fill(0) is faster then writing to each index
also b/c this looks cleaner then
recalculate () {
this._pieces.fill(0)
}then
recalculate () {
for (let i = 0; i < this._numPieces; ++i) {
this._pieces[i] = 0
}
}
lib/rarity-map.js
Outdated
| var self = this | ||
| class RarityMap { | ||
| constructor (torrent) { | ||
| const self = this |
This comment has been minimized.
This comment has been minimized.
lib/rarity-map.js
Outdated
| } else { | ||
| return -1 | ||
| destroy () { | ||
| const self = this |
This comment has been minimized.
This comment has been minimized.
| let min = Infinity | ||
|
|
||
| for (let i = 0; i < this._numPieces; ++i) { | ||
| if (pieceFilterFunc && !pieceFilterFunc(i)) continue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
So clean, so nice. LGTM |
lib/rarity-map.js
Outdated
| constructor (torrent) { | ||
| this._torrent = torrent | ||
| this._numPieces = torrent.pieces.length | ||
| this._pieces = new Array(this._numPieces).fill(0) |
This comment has been minimized.
This comment has been minimized.
DiegoRBaquero
Aug 26, 2018
Member
What is the fill here for? If it's not needed I think it will just consume O(n) to fill it and can be removed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.

jimmywarting commentedAug 26, 2018
#1443