Unverified Commit 41c60633 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Sped up Element._sort (#104103)

parent ec20ea80
...@@ -3191,15 +3191,21 @@ abstract class Element extends DiagnosticableTree implements BuildContext { ...@@ -3191,15 +3191,21 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
} }
late int _depth; late int _depth;
/// Returns result < 0 when [a] < [b], result == 0 when [a] == [b], result > 0
/// when [a] > [b].
static int _sort(Element a, Element b) { static int _sort(Element a, Element b) {
if (a.depth < b.depth) final int diff = a.depth - b.depth;
return -1; // If depths are not equal, return the difference.
if (b.depth < a.depth) if (diff != 0) {
return 1; return diff;
if (b.dirty && !a.dirty) }
return -1; // If the `dirty` values are not equal, sort with non-dirty elements being
if (a.dirty && !b.dirty) // less than dirty elements.
return 1; final bool isBDirty = b.dirty;
if (a.dirty != isBDirty) {
return isBDirty ? -1 : 1;
}
// Otherwise, `depth`s and `dirty`s are equal.
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment