File tree Expand file tree Collapse file tree 1 file changed +26
-21
lines changed Expand file tree Collapse file tree 1 file changed +26
-21
lines changed Original file line number Diff line number Diff line change @@ -1872,28 +1872,33 @@ pub const unsafe fn encode_utf8_raw_unchecked(code: u32, dst: *mut u8) {
1872
1872
// SAFETY: The caller must guarantee that the buffer pointed to by `dst`
1873
1873
// is at least `len` bytes long.
1874
1874
unsafe {
1875
- match len {
1876
- 1 => {
1877
- * dst = code as u8 ;
1878
- }
1879
- 2 => {
1880
- * dst = ( code >> 6 & 0x1F ) as u8 | TAG_TWO_B ;
1881
- * dst. add ( 1 ) = ( code & 0x3F ) as u8 | TAG_CONT ;
1882
- }
1883
- 3 => {
1884
- * dst = ( code >> 12 & 0x0F ) as u8 | TAG_THREE_B ;
1885
- * dst. add ( 1 ) = ( code >> 6 & 0x3F ) as u8 | TAG_CONT ;
1886
- * dst. add ( 2 ) = ( code & 0x3F ) as u8 | TAG_CONT ;
1887
- }
1888
- 4 => {
1889
- * dst = ( code >> 18 & 0x07 ) as u8 | TAG_FOUR_B ;
1890
- * dst. add ( 1 ) = ( code >> 12 & 0x3F ) as u8 | TAG_CONT ;
1891
- * dst. add ( 2 ) = ( code >> 6 & 0x3F ) as u8 | TAG_CONT ;
1892
- * dst. add ( 3 ) = ( code & 0x3F ) as u8 | TAG_CONT ;
1893
- }
1894
- // SAFETY: `char` always takes between 1 and 4 bytes to encode in UTF-8.
1895
- _ => crate :: hint:: unreachable_unchecked ( ) ,
1875
+ if len == 1 {
1876
+ * dst = code as u8 ;
1877
+ return ;
1878
+ }
1879
+
1880
+ let last1 = ( code >> 0 & 0x3F ) as u8 | TAG_CONT ;
1881
+ let last2 = ( code >> 6 & 0x3F ) as u8 | TAG_CONT ;
1882
+ let last3 = ( code >> 12 & 0x3F ) as u8 | TAG_CONT ;
1883
+ let last4 = ( code >> 18 & 0x3F ) as u8 | TAG_FOUR_B ;
1884
+
1885
+ if len == 2 {
1886
+ * dst = last2 | TAG_TWO_B ;
1887
+ * dst. add ( 1 ) = last1;
1888
+ return ;
1896
1889
}
1890
+
1891
+ if len == 3 {
1892
+ * dst = last3 | TAG_THREE_B ;
1893
+ * dst. add ( 1 ) = last2;
1894
+ * dst. add ( 2 ) = last1;
1895
+ return ;
1896
+ }
1897
+
1898
+ * dst = last4;
1899
+ * dst. add ( 1 ) = last3;
1900
+ * dst. add ( 2 ) = last2;
1901
+ * dst. add ( 3 ) = last1;
1897
1902
}
1898
1903
}
1899
1904
You can’t perform that action at this time.
0 commit comments