@@ -12,6 +12,7 @@ pub struct TextUnit(u32);
12
12
13
13
impl TextUnit {
14
14
/// `TextUnit` equal to the length of this char.
15
+ #[ inline( always) ]
15
16
pub fn of_char ( c : char ) -> TextUnit {
16
17
TextUnit ( c. len_utf8 ( ) as u32 )
17
18
}
@@ -20,6 +21,7 @@ impl TextUnit {
20
21
///
21
22
/// # Panics
22
23
/// Panics if the length of the string is greater than `u32::max_value()`
24
+ #[ inline( always) ]
23
25
pub fn of_str ( s : & str ) -> TextUnit {
24
26
if s. len ( ) > u32:: max_value ( ) as usize {
25
27
panic ! ( "string is to long" )
@@ -35,18 +37,21 @@ impl fmt::Debug for TextUnit {
35
37
}
36
38
37
39
impl fmt:: Display for TextUnit {
40
+ #[ inline( always) ]
38
41
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
39
42
self . 0 . fmt ( f)
40
43
}
41
44
}
42
45
43
46
impl From < TextUnit > for u32 {
47
+ #[ inline( always) ]
44
48
fn from ( tu : TextUnit ) -> u32 {
45
49
tu. 0
46
50
}
47
51
}
48
52
49
53
impl From < u32 > for TextUnit {
54
+ #[ inline( always) ]
50
55
fn from ( tu : u32 ) -> TextUnit {
51
56
TextUnit ( tu)
52
57
}
@@ -57,39 +62,45 @@ macro_rules! ops_impls {
57
62
58
63
impl ops:: $T<TextUnit > for TextUnit {
59
64
type Output = TextUnit ;
65
+ #[ inline( always) ]
60
66
fn $f( self , rhs: TextUnit ) -> TextUnit {
61
67
TextUnit ( self . 0 $op rhs. 0 )
62
68
}
63
69
}
64
70
65
71
impl <' a> ops:: $T<& ' a TextUnit > for TextUnit {
66
72
type Output = TextUnit ;
73
+ #[ inline( always) ]
67
74
fn $f( self , rhs: & ' a TextUnit ) -> TextUnit {
68
75
ops:: $T:: $f( self , * rhs)
69
76
}
70
77
}
71
78
72
79
impl <' a> ops:: $T<TextUnit > for & ' a TextUnit {
73
80
type Output = TextUnit ;
81
+ #[ inline( always) ]
74
82
fn $f( self , rhs: TextUnit ) -> TextUnit {
75
83
ops:: $T:: $f( * self , rhs)
76
84
}
77
85
}
78
86
79
87
impl <' a, ' b> ops:: $T<& ' a TextUnit > for & ' b TextUnit {
80
88
type Output = TextUnit ;
89
+ #[ inline( always) ]
81
90
fn $f( self , rhs: & ' a TextUnit ) -> TextUnit {
82
91
ops:: $T:: $f( * self , * rhs)
83
92
}
84
93
}
85
94
86
95
impl ops:: $AT<TextUnit > for TextUnit {
96
+ #[ inline( always) ]
87
97
fn $af( & mut self , rhs: TextUnit ) {
88
98
self . 0 = self . 0 $op rhs. 0
89
99
}
90
100
}
91
101
92
102
impl <' a> ops:: $AT<& ' a TextUnit > for TextUnit {
103
+ #[ inline( always) ]
93
104
fn $af( & mut self , rhs: & ' a TextUnit ) {
94
105
ops:: $AT:: $af( self , * rhs)
95
106
}
@@ -137,6 +148,7 @@ impl fmt::Display for TextRange {
137
148
138
149
impl TextRange {
139
150
/// The left-inclusive range (`[from..to)`) between to points in the text
151
+ #[ inline( always) ]
140
152
pub fn from_to ( from : TextUnit , to : TextUnit ) -> TextRange {
141
153
assert ! ( from <= to, "Invalid text range [{}; {})" , from, to) ;
142
154
TextRange {
@@ -146,26 +158,31 @@ impl TextRange {
146
158
}
147
159
148
160
/// The left-inclusive range (`[offset..offset + len)`) between to points in the text
161
+ #[ inline( always) ]
149
162
pub fn offset_len ( offset : TextUnit , len : TextUnit ) -> TextRange {
150
163
TextRange :: from_to ( offset, offset + len)
151
164
}
152
165
153
166
/// The inclusive start of this range
167
+ #[ inline( always) ]
154
168
pub fn start ( & self ) -> TextUnit {
155
169
self . start
156
170
}
157
171
158
172
/// The exclusive end of this range
173
+ #[ inline( always) ]
159
174
pub fn end ( & self ) -> TextUnit {
160
175
self . end
161
176
}
162
177
163
178
/// The length of this range
179
+ #[ inline( always) ]
164
180
pub fn len ( & self ) -> TextUnit {
165
181
self . end - self . start
166
182
}
167
183
168
184
/// Is this range empty of any content?
185
+ #[ inline( always) ]
169
186
pub fn is_empty ( & self ) -> bool {
170
187
self . start ( ) == self . end ( )
171
188
}
0 commit comments