Skip to content

Commit

Permalink
Engine Improvement: Prioritize longer segments for connectionReuse
Browse files Browse the repository at this point in the history
  • Loading branch information
AminBhst committed Dec 8, 2024
1 parent 43ca6cc commit 275778c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/src/download_engine/http_download_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ class HttpDownloadEngine {
);
return;
}
nodes.sort((a, b) => a.lastUpdateMillis.compareTo(b.lastUpdateMillis));
nodes.sort((a, b) => a.segment.length.compareTo(b.segment.length));
final targetNode = nodes
.where((node) => node.segment != connectionChannel.segment)
.toList()
.lastOrNull;
.firstOrNull;
if (targetNode == null) {
logger?.error(
"_sendRefreshSegmentCommand_ReuseConnection:: Fatal! Target node is null!",
Expand Down
16 changes: 8 additions & 8 deletions lib/src/download_engine/segment/segment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ class Segment {

Segment(this.startByte, this.endByte);

get length => this.endByte - this.startByte + 1;
int get length => endByte - startByte + 1;

@override
String toString() {
return "startByte: $startByte endByte: $endByte";
}

bool isInRangeOfOther(Segment other) {
return this.startByte >= other.startByte && this.endByte <= other.endByte;
return startByte >= other.startByte && endByte <= other.endByte;
}

bool overlapsWithOther(Segment other) {
return this.startByte <= other.startByte && this.endByte >= other.startByte;
return startByte <= other.startByte && endByte >= other.startByte;
}

bool get isValid =>
this.startByte != this.endByte &&
this.startByte < this.endByte &&
this.startByte + 1 < this.endByte;
startByte != endByte &&
startByte < endByte &&
startByte + 1 < endByte;

@override
bool operator ==(Object other) {
return (other is Segment) &&
other.startByte == this.startByte &&
other.endByte == this.endByte;
other.startByte == startByte &&
other.endByte == endByte;
}
}

0 comments on commit 275778c

Please sign in to comment.