@@ -141,14 +141,12 @@ impl Reactor {
141
141
// we need to be able to associate the index with the right waker.
142
142
143
143
// We start by iterating over the pollables, and keeping note of which
144
- // pollable belongs to which waker index
145
- let mut indexes = Vec :: with_capacity ( reactor. wakers . len ( ) ) ;
144
+ // pollable belongs to which waker
145
+ let mut indexed_wakers = Vec :: with_capacity ( reactor. wakers . len ( ) ) ;
146
146
let mut targets = Vec :: with_capacity ( reactor. wakers . len ( ) ) ;
147
- for waitee in reactor. wakers . keys ( ) {
147
+ for ( waitee, waker ) in reactor. wakers . iter ( ) {
148
148
let pollable_index = waitee. pollable . 0 . key ;
149
- // FIXME: instead of storing the indexes, we can actually just stick the waker in here,
150
- // and make the quadratic lookup at the end of this function into a linear lookup.
151
- indexes. push ( pollable_index) ;
149
+ indexed_wakers. push ( waker) ;
152
150
targets. push ( & reactor. pollables [ pollable_index. 0 ] ) ;
153
151
}
154
152
@@ -166,17 +164,12 @@ impl Reactor {
166
164
// to convert it back to the right keys for the wakers. Earlier we
167
165
// established a positional index -> waker key relationship, so we can
168
166
// go right ahead and perform a lookup there.
169
- let ready_keys = ready_indexes
167
+ let ready_wakers = ready_indexes
170
168
. into_iter ( )
171
- . map ( |index| indexes [ index as usize ] ) ;
169
+ . map ( |index| indexed_wakers [ index as usize ] ) ;
172
170
173
- // FIXME this doesn't have to be quadratic.
174
- for key in ready_keys {
175
- for ( waitee, waker) in reactor. wakers . iter ( ) {
176
- if waitee. pollable . 0 . key == key {
177
- waker. wake_by_ref ( )
178
- }
179
- }
171
+ for waker in ready_wakers {
172
+ waker. wake_by_ref ( )
180
173
}
181
174
}
182
175
0 commit comments