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

wait to notify() or updateInterest() at end of GC #1044

Merged
merged 1 commit into from Feb 14, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -893,7 +893,7 @@ Torrent.prototype.deselect = function (start, end, priority) {
for (var i = 0; i < self._selections.length; ++i) {
var s = self._selections[i]
if (s.from === start && s.to === end && s.priority === priority) {
self._selections.splice(i--, 1)
self._selections.splice(i, 1)

This comment has been minimized.

Copy link
@feross

feross Feb 14, 2017

Author Member

the -- is not needed to compensate for the splice(), since we call break right afterwards.

break
}
}
@@ -1131,22 +1131,33 @@ Torrent.prototype._updateSelections = function () {
Torrent.prototype._gcSelections = function () {
var self = this

for (var i = 0; i < self._selections.length; i++) {
var i
var toRemove = []

for (i = 0; i < self._selections.length; ++i) {
var s = self._selections[i]
var oldOffset = s.offset

// check for newly downloaded pieces in selection
while (self.bitfield.get(s.from + s.offset) && s.from + s.offset < s.to) {
s.offset++
s.offset += 1
}

if (oldOffset !== s.offset) s.notify()
if (s.to !== s.from + s.offset) continue
if (!self.bitfield.get(s.from + s.offset)) continue

// remove fully downloaded selection
self._selections.splice(i--, 1) // decrement i to offset splice
s.notify() // TODO: this may notify twice in a row. is this a problem?
toRemove.push(i)
}

if (toRemove.length > 0) {
// Since self._selections is being modified in-place, it's necessary to
// traverse `toRemove` in reverse.
for (i = toRemove.length - 1; i >= 0; --i) {
self._selections.splice(i, 1)
}
s.notify()
self._updateInterest()
}

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