@@ -191,11 +191,13 @@ impl !Send for Span {}
191
191
impl !Sync for Span { }
192
192
193
193
impl PartialOrd for Span {
194
+ #[ inline]
194
195
fn partial_cmp ( & self , rhs : & Self ) -> Option < Ordering > {
195
196
PartialOrd :: partial_cmp ( & self . data ( ) , & rhs. data ( ) )
196
197
}
197
198
}
198
199
impl Ord for Span {
200
+ #[ inline]
199
201
fn cmp ( & self , rhs : & Self ) -> Ordering {
200
202
Ord :: cmp ( & self . data ( ) , & rhs. data ( ) )
201
203
}
@@ -253,11 +255,13 @@ impl Span {
253
255
}
254
256
255
257
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
258
+ #[ inline]
256
259
pub fn substitute_dummy ( self , other : Span ) -> Span {
257
260
if self . source_equal ( & DUMMY_SP ) { other } else { self }
258
261
}
259
262
260
263
/// Return true if `self` fully encloses `other`.
264
+ #[ inline]
261
265
pub fn contains ( self , other : Span ) -> bool {
262
266
let span = self . data ( ) ;
263
267
let other = other. data ( ) ;
@@ -268,13 +272,15 @@ impl Span {
268
272
///
269
273
/// Use this instead of `==` when either span could be generated code,
270
274
/// and you only care that they point to the same bytes of source text.
275
+ #[ inline]
271
276
pub fn source_equal ( & self , other : & Span ) -> bool {
272
277
let span = self . data ( ) ;
273
278
let other = other. data ( ) ;
274
279
span. lo == other. lo && span. hi == other. hi
275
280
}
276
281
277
282
/// Returns `Some(span)`, where the start is trimmed by the end of `other`
283
+ #[ inline]
278
284
pub fn trim_start ( self , other : Span ) -> Option < Span > {
279
285
let span = self . data ( ) ;
280
286
let other = other. data ( ) ;
@@ -406,6 +412,7 @@ impl Span {
406
412
}
407
413
408
414
/// Return a `Span` between the end of `self` to the beginning of `end`.
415
+ #[ inline]
409
416
pub fn between ( self , end : Span ) -> Span {
410
417
let span = self . data ( ) ;
411
418
let end = end. data ( ) ;
@@ -417,6 +424,7 @@ impl Span {
417
424
}
418
425
419
426
/// Return a `Span` between the beginning of `self` to the beginning of `end`.
427
+ #[ inline]
420
428
pub fn until ( self , end : Span ) -> Span {
421
429
let span = self . data ( ) ;
422
430
let end = end. data ( ) ;
@@ -488,6 +496,7 @@ pub struct SpanLabel {
488
496
}
489
497
490
498
impl Default for Span {
499
+ #[ inline]
491
500
fn default ( ) -> Self {
492
501
DUMMY_SP
493
502
}
@@ -539,37 +548,43 @@ impl fmt::Debug for SpanData {
539
548
}
540
549
541
550
impl MultiSpan {
551
+ #[ inline]
542
552
pub fn new ( ) -> MultiSpan {
543
553
MultiSpan {
544
554
primary_spans : vec ! [ ] ,
545
555
span_labels : vec ! [ ]
546
556
}
547
557
}
548
558
559
+ #[ inline]
549
560
pub fn from_span ( primary_span : Span ) -> MultiSpan {
550
561
MultiSpan {
551
562
primary_spans : vec ! [ primary_span] ,
552
563
span_labels : vec ! [ ]
553
564
}
554
565
}
555
566
567
+ #[ inline]
556
568
pub fn from_spans ( vec : Vec < Span > ) -> MultiSpan {
557
569
MultiSpan {
558
570
primary_spans : vec,
559
571
span_labels : vec ! [ ]
560
572
}
561
573
}
562
574
575
+ #[ inline]
563
576
pub fn push_span_label ( & mut self , span : Span , label : String ) {
564
577
self . span_labels . push ( ( span, label) ) ;
565
578
}
566
579
567
580
/// Selects the first primary span (if any)
581
+ #[ inline]
568
582
pub fn primary_span ( & self ) -> Option < Span > {
569
583
self . primary_spans . first ( ) . cloned ( )
570
584
}
571
585
572
586
/// Returns all primary spans.
587
+ #[ inline]
573
588
pub fn primary_spans ( & self ) -> & [ Span ] {
574
589
& self . primary_spans
575
590
}
@@ -625,12 +640,14 @@ impl MultiSpan {
625
640
}
626
641
627
642
impl From < Span > for MultiSpan {
643
+ #[ inline]
628
644
fn from ( span : Span ) -> MultiSpan {
629
645
MultiSpan :: from_span ( span)
630
646
}
631
647
}
632
648
633
649
impl From < Vec < Span > > for MultiSpan {
650
+ #[ inline]
634
651
fn from ( spans : Vec < Span > ) -> MultiSpan {
635
652
MultiSpan :: from_spans ( spans)
636
653
}
@@ -659,6 +676,7 @@ pub enum NonNarrowChar {
659
676
}
660
677
661
678
impl NonNarrowChar {
679
+ #[ inline]
662
680
fn new ( pos : BytePos , width : usize ) -> Self {
663
681
match width {
664
682
0 => NonNarrowChar :: ZeroWidth ( pos) ,
@@ -669,6 +687,7 @@ impl NonNarrowChar {
669
687
}
670
688
671
689
/// Returns the absolute offset of the character in the CodeMap
690
+ #[ inline]
672
691
pub fn pos ( & self ) -> BytePos {
673
692
match * self {
674
693
NonNarrowChar :: ZeroWidth ( p) |
@@ -678,6 +697,7 @@ impl NonNarrowChar {
678
697
}
679
698
680
699
/// Returns the width of the character, 0 (zero-width) or 2 (wide)
700
+ #[ inline]
681
701
pub fn width ( & self ) -> usize {
682
702
match * self {
683
703
NonNarrowChar :: ZeroWidth ( _) => 0 ,
@@ -690,6 +710,7 @@ impl NonNarrowChar {
690
710
impl Add < BytePos > for NonNarrowChar {
691
711
type Output = Self ;
692
712
713
+ #[ inline]
693
714
fn add ( self , rhs : BytePos ) -> Self {
694
715
match self {
695
716
NonNarrowChar :: ZeroWidth ( pos) => NonNarrowChar :: ZeroWidth ( pos + rhs) ,
@@ -702,6 +723,7 @@ impl Add<BytePos> for NonNarrowChar {
702
723
impl Sub < BytePos > for NonNarrowChar {
703
724
type Output = Self ;
704
725
726
+ #[ inline]
705
727
fn sub ( self , rhs : BytePos ) -> Self {
706
728
match self {
707
729
NonNarrowChar :: ZeroWidth ( pos) => NonNarrowChar :: ZeroWidth ( pos - rhs) ,
@@ -962,6 +984,7 @@ impl FileMap {
962
984
/// and CodeMap will append a newline when adding a filemap without a newline at the end,
963
985
/// so the safe way to call this is with value calculated as
964
986
/// filemap.start_pos + newline_offset_relative_to_the_start_of_filemap.
987
+ #[ inline]
965
988
pub fn next_line ( & self , pos : BytePos ) {
966
989
// the new charpos must be > the last one (or it's the first one).
967
990
let mut lines = self . lines . borrow_mut ( ) ;
@@ -1037,6 +1060,7 @@ impl FileMap {
1037
1060
}
1038
1061
}
1039
1062
1063
+ #[ inline]
1040
1064
pub fn record_multibyte_char ( & self , pos : BytePos , bytes : usize ) {
1041
1065
assert ! ( bytes >=2 && bytes <= 4 ) ;
1042
1066
let mbc = MultiByteChar {
@@ -1046,6 +1070,7 @@ impl FileMap {
1046
1070
self . multibyte_chars . borrow_mut ( ) . push ( mbc) ;
1047
1071
}
1048
1072
1073
+ #[ inline]
1049
1074
pub fn record_width ( & self , pos : BytePos , ch : char ) {
1050
1075
let width = match ch {
1051
1076
'\t' =>
@@ -1176,12 +1201,14 @@ impl Sub for BytePos {
1176
1201
}
1177
1202
1178
1203
impl Encodable for BytePos {
1204
+ #[ inline]
1179
1205
fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
1180
1206
s. emit_u32 ( self . 0 )
1181
1207
}
1182
1208
}
1183
1209
1184
1210
impl Decodable for BytePos {
1211
+ #[ inline]
1185
1212
fn decode < D : Decoder > ( d : & mut D ) -> Result < BytePos , D :: Error > {
1186
1213
Ok ( BytePos ( d. read_u32 ( ) ?) )
1187
1214
}
0 commit comments