Skip to content

Commit eea33df

Browse files
committed
Replace 255 with u8::MAX
1 parent 9574e14 commit eea33df

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎vm/src/bytes_inner.rs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub struct ByteInnerTranslateOptions {
214214
impl ByteInnerTranslateOptions {
215215
pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Vec<u8>, Vec<u8>)> {
216216
let table = self.table.map_or_else(
217-
|| Ok((0..=255).collect::<Vec<u8>>()),
217+
|| Ok((0..=u8::MAX).collect::<Vec<u8>>()),
218218
|v| {
219219
let bytes = v
220220
.try_into_value::<PyBytesInner>(vm)
@@ -424,8 +424,8 @@ impl PyBytesInner {
424424
let mut new: Vec<u8> = Vec::with_capacity(self.elements.len());
425425
for w in &self.elements {
426426
match w {
427-
65..=90 => new.push(w.to_ascii_lowercase()),
428-
97..=122 => new.push(w.to_ascii_uppercase()),
427+
b'A'..=b'Z' => new.push(w.to_ascii_lowercase()),
428+
b'a'..=b'z' => new.push(w.to_ascii_uppercase()),
429429
x => new.push(*x),
430430
}
431431
}
@@ -491,10 +491,11 @@ impl PyBytesInner {
491491
vm: &VirtualMachine,
492492
) -> PyResult<Vec<u8>> {
493493
let (width, fillchar) = options.get_value("center", vm)?;
494-
Ok(if self.len() as isize >= width {
494+
let len = self.len();
495+
Ok(if len as isize >= width {
495496
Vec::from(&self.elements[..])
496497
} else {
497-
pad(&self.elements, width as usize, fillchar, self.len())
498+
pad(&self.elements, width as usize, fillchar, len)
498499
})
499500
}
500501

@@ -564,7 +565,7 @@ impl PyBytesInner {
564565
}
565566
let mut res = vec![];
566567

567-
for i in 0..=255 {
568+
for i in 0..=u8::MAX {
568569
res.push(if let Some(position) = from.elements.find_byte(i) {
569570
to.elements[position]
570571
} else {
@@ -929,7 +930,7 @@ impl PyBytesInner {
929930

930931
for i in &self.elements {
931932
match i {
932-
65..=90 | 97..=122 => {
933+
b'A'..=b'Z' | b'a'..=b'z' => {
933934
if spaced {
934935
res.push(i.to_ascii_uppercase());
935936
spaced = false
@@ -1011,6 +1012,7 @@ impl AnyStrWrapper<[u8]> for PyBytesInner {
10111012
fn as_ref(&self) -> Option<&[u8]> {
10121013
Some(&self.elements)
10131014
}
1015+
10141016
fn is_empty(&self) -> bool {
10151017
self.elements.is_empty()
10161018
}
@@ -1036,9 +1038,11 @@ impl anystr::AnyChar for u8 {
10361038
fn is_lowercase(self) -> bool {
10371039
self.is_ascii_lowercase()
10381040
}
1041+
10391042
fn is_uppercase(self) -> bool {
10401043
self.is_ascii_uppercase()
10411044
}
1045+
10421046
fn bytes_len(self) -> usize {
10431047
1
10441048
}

0 commit comments

Comments
 (0)