Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/task_scheduler/sequence_sort_key.h" | |
| 6 | |
| 7 namespace base { | |
| 8 namespace internal { | |
| 9 | |
| 10 SequenceSortKey::SequenceSortKey(TaskPriority priority, | |
| 11 TimeTicks next_task_sequenced_time) | |
| 12 : priority(priority), next_task_sequenced_time(next_task_sequenced_time) {} | |
| 13 | |
| 14 bool SequenceSortKey::operator<(const SequenceSortKey& other) const { | |
| 15 // This SequenceSortKey is considered less important than |other| if it has a | |
| 16 // lower priority or if it has the same priority but its next task was posted | |
| 17 // later than |other|'s. | |
| 18 const int priority_diff = | |
| 19 static_cast<TaskPriorityUnderlyingType>(priority) - | |
| 20 static_cast<TaskPriorityUnderlyingType>(other.priority); | |
| 21 return priority_diff != 0 | |
|
danakj
2016/03/15 23:16:32
not a big fan of multiline ternary if statements.
fdoray
2016/03/16 19:11:43
Done. I think the comment is still useful to expla
| |
| 22 ? priority_diff < 0 | |
| 23 : next_task_sequenced_time > other.next_task_sequenced_time; | |
| 24 } | |
| 25 | |
| 26 bool SequenceSortKey::operator>(const SequenceSortKey& other) const { | |
| 27 const int priority_diff = | |
|
danakj
2016/03/15 23:16:32
Can this not be implemented in terms of operator<?
fdoray
2016/03/16 19:11:43
Done.
| |
| 28 static_cast<TaskPriorityUnderlyingType>(priority) - | |
| 29 static_cast<TaskPriorityUnderlyingType>(other.priority); | |
| 30 return priority_diff != 0 | |
| 31 ? priority_diff > 0 | |
| 32 : next_task_sequenced_time < other.next_task_sequenced_time; | |
| 33 } | |
| 34 | |
| 35 } // namespace internal | |
| 36 } // namespace base | |
| OLD | NEW |