mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #4427 from yt2b/fix_integer_format
Fix integer format
This commit is contained in:
2 files changed
+15
-1
No files matched your search
@@ -600,7 +600,7 @@ impl FormatSpec {
|
||||
let sign_prefix = format!("{}{}", sign_str, prefix);
|
||||
let magnitude_str = self.add_magnitude_separators(raw_magnitude_str?, &sign_prefix);
|
||||
self.format_sign_and_align(
|
||||
unsafe { &BorrowedStr::from_ascii_unchecked(magnitude_str.as_bytes()) },
|
||||
&BorrowedStr::from_bytes(magnitude_str.as_bytes()),
|
||||
&sign_prefix,
|
||||
FormatAlign::Right,
|
||||
)
|
||||
|
||||
@@ -80,6 +80,20 @@ impl<'a> BorrowedStr<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_bytes(s: &'a [u8]) -> Self {
|
||||
let k = if s.is_ascii() {
|
||||
PyStrKind::Ascii.new_data()
|
||||
} else {
|
||||
PyStrKind::Utf8.new_data()
|
||||
};
|
||||
Self {
|
||||
bytes: s,
|
||||
kind: k,
|
||||
hash: PyAtomic::<PyHash>::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_str(&self) -> &str {
|
||||
unsafe {
|
||||
|
||||
Reference in new issue
Block a user