Skip to content

Commit 166e69e

Browse files
committed
Use associated constants instead of module constants.
1 parent e8736b6 commit 166e69e

File tree

8 files changed

+44
-50
lines changed

8 files changed

+44
-50
lines changed

common/src/float_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn parse_str(literal: &str) -> Option<f64> {
9797
}
9898

9999
pub fn is_integer(v: f64) -> bool {
100-
(v - v.round()).abs() < std::f64::EPSILON
100+
(v - v.round()).abs() < f64::EPSILON
101101
}
102102

103103
#[derive(Debug)]

vm/src/anystr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ fn saturate_to_isize(py_int: PyIntRef) -> isize {
6969
let big = py_int.as_bigint();
7070
big.to_isize().unwrap_or_else(|| {
7171
if big.is_negative() {
72-
std::isize::MIN
72+
isize::MIN
7373
} else {
74-
std::isize::MAX
74+
isize::MAX
7575
}
7676
})
7777
}

vm/src/builtins/pystr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl PyStr {
394394
ch if (ch as u32) < 0x10000 => 6, // \uHHHH
395395
_ => 10, // \uHHHHHHHH
396396
};
397-
if out_len > (std::isize::MAX as usize) - incr {
397+
if out_len > (isize::MAX as usize) - incr {
398398
return Err(vm.new_overflow_error("string is too long to generate repr".to_owned()));
399399
}
400400
out_len += incr;

vm/src/bytesinner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl PyBytesInner {
832832
return self.elements.clone();
833833
};
834834

835-
let mut count = maxcount.unwrap_or(std::usize::MAX) - 1;
835+
let mut count = maxcount.unwrap_or(usize::MAX) - 1;
836836
for offset in iter {
837837
new[offset..offset + len].clone_from_slice(to.elements.as_slice());
838838
count -= 1;
@@ -860,7 +860,7 @@ impl PyBytesInner {
860860
// result_len = self_len + count * (to_len-from_len)
861861
debug_assert!(count > 0);
862862
if to.len() as isize - from.len() as isize
863-
> (std::isize::MAX - self.elements.len() as isize) / count as isize
863+
> (isize::MAX - self.elements.len() as isize) / count as isize
864864
{
865865
return Err(vm.new_overflow_error("replace bytes is too long".to_owned()));
866866
}

vm/src/stdlib/cmath.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
1010
"pi" => ctx.new_float(std::f64::consts::PI),
1111
"e" => ctx.new_float(std::f64::consts::E),
1212
"tau" => ctx.new_float(2.0 * std::f64::consts::PI),
13-
"inf" => ctx.new_float(std::f64::INFINITY),
13+
"inf" => ctx.new_float(f64::INFINITY),
1414
"infj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::INFINITY)),
15-
"nan" => ctx.new_float(std::f64::NAN),
15+
"nan" => ctx.new_float(f64::NAN),
1616
"nanj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::NAN)),
1717
});
1818

vm/src/stdlib/math.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn math_gamma(x: IntoPyFloat) -> f64 {
327327
} else if x.is_nan() || x.is_sign_positive() {
328328
x
329329
} else {
330-
std::f64::NAN
330+
f64::NAN
331331
}
332332
}
333333

@@ -338,7 +338,7 @@ fn math_lgamma(x: IntoPyFloat) -> f64 {
338338
} else if x.is_nan() {
339339
x
340340
} else {
341-
std::f64::INFINITY
341+
f64::INFINITY
342342
}
343343
}
344344

@@ -822,7 +822,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
822822
"pi" => ctx.new_float(std::f64::consts::PI), // 3.14159...
823823
"e" => ctx.new_float(std::f64::consts::E), // 2.71..
824824
"tau" => ctx.new_float(2.0 * std::f64::consts::PI),
825-
"inf" => ctx.new_float(std::f64::INFINITY),
826-
"nan" => ctx.new_float(std::f64::NAN)
825+
"inf" => ctx.new_float(f64::INFINITY),
826+
"nan" => ctx.new_float(f64::NAN)
827827
})
828828
}

vm/src/stdlib/sre.rs

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod _sre {
9797
string: PyObjectRef,
9898
#[pyarg(any, default = "0")]
9999
pos: usize,
100-
#[pyarg(any, default = "std::isize::MAX as usize")]
100+
#[pyarg(any, default = "isize::MAX as usize")]
101101
endpos: usize,
102102
}
103103

@@ -340,48 +340,42 @@ mod _sre {
340340
split_args: SplitArgs,
341341
vm: &VirtualMachine,
342342
) -> PyResult<PyListRef> {
343-
zelf.with_state(
344-
split_args.string.clone(),
345-
0,
346-
std::usize::MAX,
347-
vm,
348-
|mut state| {
349-
let mut splitlist: Vec<PyObjectRef> = Vec::new();
343+
zelf.with_state(split_args.string.clone(), 0, usize::MAX, vm, |mut state| {
344+
let mut splitlist: Vec<PyObjectRef> = Vec::new();
350345

351-
let mut n = 0;
352-
let mut last = 0;
353-
while split_args.maxsplit == 0 || n < split_args.maxsplit {
354-
state = state.search();
355-
if !state.has_matched {
356-
break;
357-
}
346+
let mut n = 0;
347+
let mut last = 0;
348+
while split_args.maxsplit == 0 || n < split_args.maxsplit {
349+
state = state.search();
350+
if !state.has_matched {
351+
break;
352+
}
358353

359-
/* get segment before this match */
360-
splitlist.push(slice_drive(&state.string, last, state.start, vm));
354+
/* get segment before this match */
355+
splitlist.push(slice_drive(&state.string, last, state.start, vm));
361356

362-
let m = Match::new(&state, zelf.clone(), split_args.string.clone());
357+
let m = Match::new(&state, zelf.clone(), split_args.string.clone());
363358

364-
// add groups (if any)
365-
for i in 1..zelf.groups + 1 {
366-
splitlist.push(
367-
m.get_slice(i, state.string, vm)
368-
.unwrap_or_else(|| vm.ctx.none()),
369-
);
370-
}
371-
372-
n += 1;
373-
state.must_advance = state.string_position == state.start;
374-
last = state.string_position;
375-
state.start = state.string_position;
376-
state.reset();
359+
// add groups (if any)
360+
for i in 1..zelf.groups + 1 {
361+
splitlist.push(
362+
m.get_slice(i, state.string, vm)
363+
.unwrap_or_else(|| vm.ctx.none()),
364+
);
377365
}
378366

379-
// get segment following last match (even if empty)
380-
splitlist.push(slice_drive(&state.string, last, state.string.count(), vm));
367+
n += 1;
368+
state.must_advance = state.string_position == state.start;
369+
last = state.string_position;
370+
state.start = state.string_position;
371+
state.reset();
372+
}
381373

382-
Ok(PyList::from(splitlist).into_ref(vm))
383-
},
384-
)
374+
// get segment following last match (even if empty)
375+
splitlist.push(slice_drive(&state.string, last, state.string.count(), vm));
376+
377+
Ok(PyList::from(splitlist).into_ref(vm))
378+
})
385379
}
386380

387381
#[pymethod(magic)]
@@ -477,7 +471,7 @@ mod _sre {
477471
}
478472
};
479473

480-
zelf.with_state(string.clone(), 0, std::usize::MAX, vm, |mut state| {
474+
zelf.with_state(string.clone(), 0, usize::MAX, vm, |mut state| {
481475
let mut sublist: Vec<PyObjectRef> = Vec::new();
482476
let mut n = 0;
483477
let mut last_pos = 0;

vm/src/sysmodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
/*
1515
* The magic sys module.
1616
*/
17-
const MAXSIZE: usize = std::isize::MAX as usize;
17+
const MAXSIZE: usize = isize::MAX as usize;
1818
const MAXUNICODE: u32 = std::char::MAX as u32;
1919

2020
fn argv(vm: &VirtualMachine) -> PyObjectRef {

0 commit comments

Comments
 (0)