@@ -45,7 +45,8 @@ impl std::error::Error for Error {}
45
45
pub fn saslprep ( s : & str ) -> Result < Cow < ' _ , str > , Error > {
46
46
// fast path for ascii text
47
47
if s. chars ( )
48
- . all ( |c| c. is_ascii ( ) && !tables:: ascii_control_character ( c) ) {
48
+ . all ( |c| c. is_ascii ( ) && !tables:: ascii_control_character ( c) )
49
+ {
49
50
return Ok ( Cow :: Borrowed ( s) ) ;
50
51
}
51
52
@@ -123,6 +124,13 @@ fn is_prohibited_bidirectional_text(s: &str) -> bool {
123
124
///
124
125
/// [RFC 3491]: https://tools.ietf.org/html/rfc3491
125
126
pub fn nameprep ( s : & str ) -> Result < Cow < ' _ , str > , Error > {
127
+ // fast path for ascii text
128
+ if s. chars ( )
129
+ . all ( |c| c. is_ascii_lowercase ( ) && !tables:: ascii_control_character ( c) )
130
+ {
131
+ return Ok ( Cow :: Borrowed ( s) ) ;
132
+ }
133
+
126
134
// 3. Mapping
127
135
let mapped = s. chars ( )
128
136
. filter ( |& c| !tables:: commonly_mapped_to_nothing ( c) )
@@ -171,6 +179,15 @@ pub fn nameprep(s: &str) -> Result<Cow<'_, str>, Error> {
171
179
///
172
180
/// [RFC 3920, Appendix A]: https://tools.ietf.org/html/rfc3920#appendix-A
173
181
pub fn nodeprep ( s : & str ) -> Result < Cow < ' _ , str > , Error > {
182
+ // fast path for ascii text
183
+ if s. chars ( ) . all ( |c| {
184
+ c. is_ascii_lowercase ( )
185
+ && !tables:: ascii_control_character ( c)
186
+ && !prohibited_node_character ( c)
187
+ } ) {
188
+ return Ok ( Cow :: Borrowed ( s) ) ;
189
+ }
190
+
174
191
// A.3. Mapping
175
192
let mapped = s. chars ( )
176
193
. filter ( |& c| !tables:: commonly_mapped_to_nothing ( c) )
@@ -229,6 +246,13 @@ fn prohibited_node_character(c: char) -> bool {
229
246
///
230
247
/// [RFC 3920, Appendix B]: https://tools.ietf.org/html/rfc3920#appendix-B
231
248
pub fn resourceprep ( s : & str ) -> Result < Cow < ' _ , str > , Error > {
249
+ // fast path for ascii text
250
+ if s. chars ( )
251
+ . all ( |c| c. is_ascii ( ) && !tables:: ascii_control_character ( c) )
252
+ {
253
+ return Ok ( Cow :: Borrowed ( s) ) ;
254
+ }
255
+
232
256
// B.3. Mapping
233
257
let mapped = s. chars ( )
234
258
. filter ( |& c| !tables:: commonly_mapped_to_nothing ( c) )
0 commit comments