@@ -71,31 +71,34 @@ fn generate_thread_to_collapsed_thread_mapping(
71
71
. or_insert_with ( || ( event. timestamp , event. timestamp ) ) ;
72
72
}
73
73
// collect the the threads in order of the end time
74
- let mut end_to_thread = thread_start_and_end
74
+ let mut end_and_thread = thread_start_and_end
75
75
. iter ( )
76
76
. map ( |( & thread_id, & ( _start, end) ) | ( end, thread_id) )
77
77
. collect :: < Vec < _ > > ( ) ;
78
78
79
- end_to_thread . sort_unstable_by_key ( |& ( end, _thread_id) | end) ;
80
- let mut next_end_iter = end_to_thread . iter ( ) ;
79
+ end_and_thread . sort_unstable_by_key ( |& ( end, _thread_id) | end) ;
80
+ let mut next_end_iter = end_and_thread . iter ( ) . peekable ( ) ;
81
81
82
- // used to get the thread that was first to end
83
- let & ( temp_next_end, temp_next_thread_id) = next_end_iter. next ( ) . unwrap ( ) ;
84
- let mut next_end = temp_next_end;
85
- let mut next_thread_id = temp_next_thread_id;
82
+ // collect the the threads in order of the start time
83
+ let mut start_and_thread = thread_start_and_end
84
+ . iter ( )
85
+ . map ( |( & thread_id, & ( start, _end) ) | ( start, thread_id) )
86
+ . collect :: < Vec < _ > > ( ) ;
87
+
88
+ start_and_thread. sort_unstable_by_key ( |& ( start, _thread_id) | start) ;
86
89
87
90
let mut current_thread_id = 0 ; // use new thread_ids to avoid strange gaps in the numbers
88
- for ( & thread_id, & ( start, _end) ) in thread_start_and_end. iter ( ) {
89
- if start > next_end {
91
+ for & ( start, thread_id) in start_and_thread. iter ( ) {
92
+ // safe to unwrap due to end_and_thread and start_and_thread have the same length
93
+ let ( next_end, next_thread_id) = next_end_iter. peek ( ) . unwrap ( ) ;
94
+ if start > * next_end {
95
+ next_end_iter. next ( ) ;
90
96
// need to lookup the thread_id due to new and collapsed threads
91
97
let mapped_thread_id = * thread_to_collapsed_thread
92
98
. get ( & next_thread_id)
93
99
. unwrap_or ( & next_thread_id) ;
94
100
95
101
thread_to_collapsed_thread. insert ( thread_id, mapped_thread_id) ;
96
- let & ( temp_next_end, temp_next_thread_id) = next_end_iter. next ( ) . unwrap ( ) ;
97
- next_end = temp_next_end;
98
- next_thread_id = temp_next_thread_id;
99
102
} else {
100
103
thread_to_collapsed_thread. insert ( thread_id, current_thread_id) ;
101
104
current_thread_id += 1 ;
0 commit comments