File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -180,9 +180,9 @@ pub const NON_ALPHANUMERIC: &AsciiSet = &CONTROLS
180
180
/// assert_eq!("foo bar".bytes().map(percent_encode_byte).collect::<String>(),
181
181
/// "%66%6F%6F%20%62%61%72");
182
182
/// ```
183
+ #[ inline]
183
184
pub fn percent_encode_byte ( byte : u8 ) -> & ' static str {
184
- let index = usize:: from ( byte) * 3 ;
185
- & "\
185
+ static ENC_TABLE : & [ u8 ; 768 ] = b"\
186
186
%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F\
187
187
%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F\
188
188
%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2F\
@@ -199,7 +199,12 @@ pub fn percent_encode_byte(byte: u8) -> &'static str {
199
199
%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF\
200
200
%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF\
201
201
%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF\
202
- "[ index..index + 3 ]
202
+ ";
203
+
204
+ let index = usize:: from ( byte) * 3 ;
205
+ // SAFETY: ENC_TABLE is ascii-only, so any subset if it should be
206
+ // ascii-only too, which is valid utf8.
207
+ unsafe { str:: from_utf8_unchecked ( & ENC_TABLE [ index..index + 3 ] ) }
203
208
}
204
209
205
210
/// Percent-encode the given bytes with the given set.
You can’t perform that action at this time.
0 commit comments