@@ -46,15 +46,15 @@ macro_rules! compare {
4646 }
4747}
4848
49- /// Sort mappings by their generated locations, breaking ties by their original
50- /// locations.
49+ /// Sort mappings by their generated location, but don't compare generated
50+ /// lines. This is useful for when we know that all mappings being sorted have
51+ /// the same generated line number.
5152#[ derive( Debug ) ]
52- pub struct ByGeneratedLocation ;
53+ pub struct ByGeneratedTail ;
5354
54- impl ComparatorFunction < Mapping > for ByGeneratedLocation {
55+ impl ComparatorFunction < Mapping > for ByGeneratedTail {
5556 #[ inline]
5657 fn compare ( a : & Mapping , b : & Mapping ) -> Ordering {
57- compare ! ( a. generated_line, b. generated_line) ;
5858 compare ! ( a. generated_column, b. generated_column) ;
5959 ByOriginalLocation :: compare ( & a. original , & b. original )
6060 }
@@ -89,3 +89,33 @@ impl ComparatorFunction<OriginalLocation> for ByOriginalLocation {
8989 a. name . cmp ( & b. name )
9090 }
9191}
92+
93+ /// Assuming mappings are in the same original source, sort mappings by their
94+ /// original locations, breaking ties by their generated locations.
95+ #[ derive( Debug ) ]
96+ pub struct ByOriginalLocationSameSource ;
97+
98+ impl ComparatorFunction < Mapping > for ByOriginalLocationSameSource {
99+ #[ inline]
100+ fn compare ( a : & Mapping , b : & Mapping ) -> Ordering {
101+ let c = ByOriginalLocationSameSource :: compare ( & a. original , & b. original ) ;
102+ match c {
103+ Ordering :: Less | Ordering :: Greater => c,
104+ Ordering :: Equal => {
105+ compare ! ( a. generated_line, b. generated_line) ;
106+ compare ! ( a. generated_column, b. generated_column) ;
107+ Ordering :: Equal
108+ }
109+ }
110+ }
111+ }
112+
113+ impl ComparatorFunction < OriginalLocation > for ByOriginalLocationSameSource {
114+ #[ inline]
115+ fn compare ( a : & OriginalLocation , b : & OriginalLocation ) -> Ordering {
116+ debug_assert_eq ! ( a. source, b. source) ;
117+ compare ! ( a. original_line, b. original_line) ;
118+ compare ! ( a. original_column, b. original_column) ;
119+ a. name . cmp ( & b. name )
120+ }
121+ }
0 commit comments