@@ -53,48 +53,26 @@ const _addNodeToTrashList = Symbol.for('addNodeToTrashList')
53
53
// they'll affect things deeper in, then alphabetical for consistency between
54
54
// installs
55
55
class DepsQueue {
56
- // [{ sorted, items }] indexed by depth
57
56
#deps = [ ]
58
57
#sorted = true
59
- #minDepth = 0
60
- #length = 0
61
58
62
59
get length ( ) {
63
- return this . #length
60
+ return this . #deps . length
64
61
}
65
62
66
63
push ( item ) {
67
- if ( ! this . #deps[ item . depth ] ) {
68
- this . #length++
69
- this . #deps[ item . depth ] = { sorted : true , items : [ item ] }
70
- // no minDepth check needed, this branch is only reached when we are in
71
- // the middle of a shallower depth and creating a new one
72
- return
73
- }
74
- if ( ! this . #deps[ item . depth ] . items . includes ( item ) ) {
75
- this . #length++
76
- this . #deps[ item . depth ] . sorted = false
77
- this . #deps[ item . depth ] . items . push ( item )
78
- if ( item . depth < this . #minDepth) {
79
- this . #minDepth = item . depth
80
- }
64
+ if ( ! this . #deps. includes ( item ) ) {
65
+ this . #sorted = false
66
+ this . #deps. push ( item )
81
67
}
82
68
}
83
69
84
70
pop ( ) {
85
- let depth
86
- while ( ! depth ?. items . length ) {
87
- depth = this . #deps[ this . #minDepth]
88
- if ( ! depth ?. items . length ) {
89
- this . #minDepth++
90
- }
91
- }
92
- if ( ! depth . sorted ) {
93
- depth . items . sort ( ( a , b ) => localeCompare ( a . path , b . path ) )
94
- depth . sorted = true
71
+ if ( ! this . #sorted) {
72
+ this . #deps. sort ( ( a , b ) => ( a . depth - b . depth ) || localeCompare ( a . path , b . path ) )
73
+ this . #sorted = true
95
74
}
96
- this . #length--
97
- return depth . items . shift ( )
75
+ return this . #deps. shift ( )
98
76
}
99
77
}
100
78
0 commit comments