From 399d699f0fa04c30cbe315d6abcd778e6d7bd22d Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Wed, 18 Nov 2020 20:48:55 +0100 Subject: [PATCH] - fix top processes sorting in the Network module (#150) --- Modules/Net/readers.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Modules/Net/readers.swift b/Modules/Net/readers.swift index 9b434ec2..f1586398 100644 --- a/Modules/Net/readers.swift +++ b/Modules/Net/readers.swift @@ -311,13 +311,17 @@ public class ProcessReader: Reader<[Network_Process]> { } processes.sort { - if $0.download != $1.download { - return $0.download < $1.download - } else if $0.upload < $1.upload { - return $0.upload < $1.upload - } else { + let firstMax = max($0.download, $0.upload) + let secondMax = max($1.download, $1.upload) + let firstMin = min($0.download, $0.upload) + let secondMin = min($1.download, $1.upload) + + if firstMax == secondMax && firstMin == secondMin { // download and upload values are the same, sort by time return $0.time < $1.time + } else if firstMax == secondMax && firstMin != secondMin { // max values are the same, min not. Sort by min values + return firstMin < secondMin } + return firstMax < secondMax // max values are not the same, sort by max value } self.callback(processes.suffix(self.numberOfProcesses).reversed())