File tree 2 files changed +15
-1
lines changed 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -600,7 +600,7 @@ impl FormatSpec {
600
600
let sign_prefix = format ! ( "{}{}" , sign_str, prefix) ;
601
601
let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str?, & sign_prefix) ;
602
602
self . format_sign_and_align (
603
- unsafe { & BorrowedStr :: from_ascii_unchecked ( magnitude_str. as_bytes ( ) ) } ,
603
+ & BorrowedStr :: from_bytes ( magnitude_str. as_bytes ( ) ) ,
604
604
& sign_prefix,
605
605
FormatAlign :: Right ,
606
606
)
Original file line number Diff line number Diff line change @@ -80,6 +80,20 @@ impl<'a> BorrowedStr<'a> {
80
80
}
81
81
}
82
82
83
+ #[ inline]
84
+ pub fn from_bytes ( s : & ' a [ u8 ] ) -> Self {
85
+ let k = if s. is_ascii ( ) {
86
+ PyStrKind :: Ascii . new_data ( )
87
+ } else {
88
+ PyStrKind :: Utf8 . new_data ( )
89
+ } ;
90
+ Self {
91
+ bytes : s,
92
+ kind : k,
93
+ hash : PyAtomic :: < PyHash > :: new ( 0 ) ,
94
+ }
95
+ }
96
+
83
97
#[ inline]
84
98
pub fn as_str ( & self ) -> & str {
85
99
unsafe {
You can’t perform that action at this time.
0 commit comments