@@ -154,6 +154,7 @@ trait CheckRaw {
154
154
impl CheckRaw for str {
155
155
type RawUnit = char ;
156
156
157
+ #[ inline]
157
158
fn char2raw_unit ( c : char ) -> Result < Self :: RawUnit , EscapeError > {
158
159
Ok ( c)
159
160
}
@@ -162,12 +163,14 @@ impl CheckRaw for str {
162
163
impl CheckRaw for [ u8 ] {
163
164
type RawUnit = u8 ;
164
165
166
+ #[ inline]
165
167
fn char2raw_unit ( c : char ) -> Result < Self :: RawUnit , EscapeError > {
166
168
char2byte ( c)
167
169
}
168
170
}
169
171
170
172
/// Turn an ascii char into a byte
173
+ #[ inline]
171
174
fn char2byte ( c : char ) -> Result < u8 , EscapeError > {
172
175
// do NOT do: c.try_into().ok_or(EscapeError::NonAsciiCharInByte)
173
176
if c. is_ascii ( ) {
@@ -180,6 +183,7 @@ fn char2byte(c: char) -> Result<u8, EscapeError> {
180
183
impl CheckRaw for CStr {
181
184
type RawUnit = char ;
182
185
186
+ #[ inline]
183
187
fn char2raw_unit ( c : char ) -> Result < Self :: RawUnit , EscapeError > {
184
188
if c == '\0' {
185
189
Err ( EscapeError :: NulInCStr )
@@ -193,6 +197,7 @@ impl CheckRaw for CStr {
193
197
///
194
198
/// Takes the contents of a char literal (without quotes),
195
199
/// and returns an unescaped char or an error.
200
+ #[ inline]
196
201
pub fn unescape_char ( src : & str ) -> Result < char , EscapeError > {
197
202
str:: unescape_single ( & mut src. chars ( ) )
198
203
}
@@ -201,6 +206,7 @@ pub fn unescape_char(src: &str) -> Result<char, EscapeError> {
201
206
///
202
207
/// Takes the contents of a byte literal (without quotes),
203
208
/// and returns an unescaped byte or an error.
209
+ #[ inline]
204
210
pub fn unescape_byte ( src : & str ) -> Result < u8 , EscapeError > {
205
211
<[ u8 ] >:: unescape_single ( & mut src. chars ( ) )
206
212
}
@@ -258,12 +264,14 @@ pub enum MixedUnit {
258
264
}
259
265
260
266
impl From < char > for MixedUnit {
267
+ #[ inline]
261
268
fn from ( c : char ) -> Self {
262
269
MixedUnit :: Char ( c)
263
270
}
264
271
}
265
272
266
273
impl From < u8 > for MixedUnit {
274
+ #[ inline]
267
275
fn from ( n : u8 ) -> Self {
268
276
if n. is_ascii ( ) {
269
277
MixedUnit :: Char ( n as char )
@@ -364,6 +372,7 @@ trait Unescape {
364
372
/// Interpret a non-nul ASCII escape
365
373
///
366
374
/// Parses the character of an ASCII escape (except nul) without the leading backslash.
375
+ #[ inline] // single use in Unescape::unescape_1
367
376
fn simple_escape ( c : char ) -> Result < u8 , char > {
368
377
// Previous character was '\\', unescape what follows.
369
378
Ok ( match c {
@@ -380,6 +389,7 @@ fn simple_escape(c: char) -> Result<u8, char> {
380
389
/// Interpret a hexadecimal escape
381
390
///
382
391
/// Parses the two hexadecimal characters of a hexadecimal escape without the leading r"\x".
392
+ #[ inline] // single use in Unescape::unescape_1
383
393
fn hex_escape ( chars : & mut impl Iterator < Item = char > ) -> Result < u8 , EscapeError > {
384
394
let hi = chars. next ( ) . ok_or ( EscapeError :: TooShortHexEscape ) ?;
385
395
let hi = hi. to_digit ( 16 ) . ok_or ( EscapeError :: InvalidCharInHexEscape ) ?;
@@ -394,6 +404,7 @@ fn hex_escape(chars: &mut impl Iterator<Item = char>) -> Result<u8, EscapeError>
394
404
///
395
405
/// Parse the braces with hexadecimal characters (and underscores) part of a unicode escape.
396
406
/// This r"{...}" normally comes after r"\u" and cannot start with an underscore.
407
+ #[ inline] // single use in Unescape::unescape_1
397
408
fn unicode_escape ( chars : & mut impl Iterator < Item = char > ) -> Result < u32 , EscapeError > {
398
409
if chars. next ( ) != Some ( '{' ) {
399
410
return Err ( EscapeError :: NoBraceInUnicodeEscape ) ;
@@ -444,10 +455,12 @@ fn unicode_escape(chars: &mut impl Iterator<Item = char>) -> Result<u32, EscapeE
444
455
/// Skip ASCII whitespace, except for the formfeed character
445
456
/// (see [this issue](https://github.com/rust-lang/rust/issues/136600)).
446
457
/// Warns on unescaped newline and following non-ASCII whitespace.
447
- fn skip_ascii_whitespace < F > ( chars : & mut Chars < ' _ > , start : usize , mut callback : F )
448
- where
449
- F : FnMut ( Range < usize > , EscapeError ) ,
450
- {
458
+ #[ inline] // single use in Unescape::unescape
459
+ fn skip_ascii_whitespace (
460
+ chars : & mut Chars < ' _ > ,
461
+ start : usize ,
462
+ mut callback : impl FnMut ( Range < usize > , EscapeError ) ,
463
+ ) {
451
464
let rest = chars. as_str ( ) ;
452
465
let first_non_space = rest
453
466
. bytes ( )
@@ -476,10 +489,12 @@ impl Unescape for str {
476
489
477
490
const ZERO_RESULT : Result < Self :: Unit , EscapeError > = Ok ( '\0' ) ;
478
491
492
+ #[ inline]
479
493
fn char2unit ( c : char ) -> Result < Self :: Unit , EscapeError > {
480
494
Ok ( c)
481
495
}
482
496
497
+ #[ inline]
483
498
fn hex2unit ( b : u8 ) -> Result < Self :: Unit , EscapeError > {
484
499
if b. is_ascii ( ) {
485
500
Ok ( b as char )
@@ -488,7 +503,7 @@ impl Unescape for str {
488
503
}
489
504
}
490
505
491
- /// Converts the result of a unicode escape to the unit type
506
+ # [ inline ]
492
507
fn unicode2unit ( r : Result < char , EscapeError > ) -> Result < Self :: Unit , EscapeError > {
493
508
r
494
509
}
@@ -499,15 +514,17 @@ impl Unescape for [u8] {
499
514
500
515
const ZERO_RESULT : Result < Self :: Unit , EscapeError > = Ok ( b'\0' ) ;
501
516
517
+ #[ inline]
502
518
fn char2unit ( c : char ) -> Result < Self :: Unit , EscapeError > {
503
519
char2byte ( c)
504
520
}
505
521
522
+ #[ inline]
506
523
fn hex2unit ( b : u8 ) -> Result < Self :: Unit , EscapeError > {
507
524
Ok ( b)
508
525
}
509
526
510
- /// Converts the result of a unicode escape to the unit type
527
+ # [ inline ]
511
528
fn unicode2unit ( _r : Result < char , EscapeError > ) -> Result < Self :: Unit , EscapeError > {
512
529
Err ( EscapeError :: UnicodeEscapeInByte )
513
530
}
@@ -518,6 +535,7 @@ impl Unescape for CStr {
518
535
519
536
const ZERO_RESULT : Result < Self :: Unit , EscapeError > = Err ( EscapeError :: NulInCStr ) ;
520
537
538
+ #[ inline]
521
539
fn char2unit ( c : char ) -> Result < Self :: Unit , EscapeError > {
522
540
if c == '\0' {
523
541
Err ( EscapeError :: NulInCStr )
@@ -526,6 +544,7 @@ impl Unescape for CStr {
526
544
}
527
545
}
528
546
547
+ #[ inline]
529
548
fn hex2unit ( byte : u8 ) -> Result < Self :: Unit , EscapeError > {
530
549
if byte == b'\0' {
531
550
Err ( EscapeError :: NulInCStr )
@@ -536,7 +555,7 @@ impl Unescape for CStr {
536
555
}
537
556
}
538
557
539
- /// Converts the result of a unicode escape to the unit type
558
+ # [ inline ]
540
559
fn unicode2unit ( r : Result < char , EscapeError > ) -> Result < Self :: Unit , EscapeError > {
541
560
Self :: char2unit ( r?)
542
561
}
0 commit comments