Skip to content

Commit e6f5b6a

Browse files
ShaharNavehyouknowone
authored andcommitted
constify a bunch of methods
1 parent 55740b2 commit e6f5b6a

7 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎vm/src/function/argument.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ pub trait FromArgOptional {
302302
type Inner: TryFromObject;
303303
fn from_inner(x: Self::Inner) -> Self;
304304
}
305+
305306
impl<T: TryFromObject> FromArgOptional for OptionalArg<T> {
306307
type Inner = T;
307308
fn from_inner(x: T) -> Self {
308309
Self::Present(x)
309310
}
310311
}
312+
311313
impl<T: TryFromObject> FromArgOptional for T {
312314
type Inner = Self;
313315
fn from_inner(x: Self) -> Self {
@@ -342,7 +344,7 @@ where
342344
}
343345

344346
impl<T> KwArgs<T> {
345-
pub fn new(map: IndexMap<String, T>) -> Self {
347+
pub const fn new(map: IndexMap<String, T>) -> Self {
346348
KwArgs(map)
347349
}
348350

@@ -354,11 +356,13 @@ impl<T> KwArgs<T> {
354356
self.0.is_empty()
355357
}
356358
}
359+
357360
impl<T> FromIterator<(String, T)> for KwArgs<T> {
358361
fn from_iter<I: IntoIterator<Item = (String, T)>>(iter: I) -> Self {
359362
KwArgs(iter.into_iter().collect())
360363
}
361364
}
365+
362366
impl<T> Default for KwArgs<T> {
363367
fn default() -> Self {
364368
KwArgs(IndexMap::new())
@@ -408,7 +412,7 @@ where
408412
}
409413

410414
impl<T> PosArgs<T> {
411-
pub fn new(args: Vec<T>) -> Self {
415+
pub const fn new(args: Vec<T>) -> Self {
412416
Self(args)
413417
}
414418

‎vm/src/function/buffer.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ impl ArgBytesLike {
5151
f(&self.borrow_buf())
5252
}
5353

54-
pub fn len(&self) -> usize {
54+
pub const fn len(&self) -> usize {
5555
self.0.desc.len
5656
}
5757

58-
pub fn is_empty(&self) -> bool {
58+
pub const fn is_empty(&self) -> bool {
5959
self.len() == 0
6060
}
6161

@@ -103,11 +103,11 @@ impl ArgMemoryBuffer {
103103
f(&mut self.borrow_buf_mut())
104104
}
105105

106-
pub fn len(&self) -> usize {
106+
pub const fn len(&self) -> usize {
107107
self.0.desc.len
108108
}
109109

110-
pub fn is_empty(&self) -> bool {
110+
pub const fn is_empty(&self) -> bool {
111111
self.len() == 0
112112
}
113113
}

‎vm/src/object/core.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ pub struct PyObject(PyInner<Erased>);
491491

492492
impl Deref for PyObjectRef {
493493
type Target = PyObject;
494+
494495
#[inline(always)]
495496
fn deref(&self) -> &PyObject {
496497
unsafe { self.ptr.as_ref() }

‎vm/src/object/ext.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ where
4747
fmt::Display::fmt(&**self, f)
4848
}
4949
}
50+
5051
impl<T: fmt::Display> fmt::Display for Py<T>
5152
where
5253
T: PyObjectPayload + fmt::Display,
@@ -72,6 +73,7 @@ impl<T: PyPayload> PyExact<T> {
7273

7374
impl<T: PyPayload> Deref for PyExact<T> {
7475
type Target = Py<T>;
76+
7577
#[inline(always)]
7678
fn deref(&self) -> &Py<T> {
7779
&self.inner
@@ -108,6 +110,7 @@ impl<T: PyObjectPayload> AsRef<Py<T>> for PyExact<T> {
108110

109111
impl<T: PyPayload> std::borrow::ToOwned for PyExact<T> {
110112
type Owned = PyRefExact<T>;
113+
111114
fn to_owned(&self) -> Self::Owned {
112115
let owned = self.inner.to_owned();
113116
unsafe { PyRefExact::new_unchecked(owned) }
@@ -181,6 +184,7 @@ impl<T: PyPayload> TryFromObject for PyRefExact<T> {
181184

182185
impl<T: PyPayload> Deref for PyRefExact<T> {
183186
type Target = PyExact<T>;
187+
184188
#[inline(always)]
185189
fn deref(&self) -> &PyExact<T> {
186190
unsafe { PyExact::ref_unchecked(self.inner.deref()) }

‎vm/src/object/traverse.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ unsafe impl<A: Traverse> Traverse for (A,) {
158158
self.0.traverse(tracer_fn);
159159
}
160160
}
161+
161162
trace_tuple!((A, 0), (B, 1));
162163
trace_tuple!((A, 0), (B, 1), (C, 2));
163164
trace_tuple!((A, 0), (B, 1), (C, 2), (D, 3));

‎vm/src/protocol/number.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub type PyNumberTernaryFunc = fn(&PyObject, &PyObject, &PyObject, &VirtualMachi
1818

1919
impl PyObject {
2020
#[inline]
21-
pub fn to_number(&self) -> PyNumber<'_> {
21+
pub const fn to_number(&self) -> PyNumber<'_> {
2222
PyNumber(self)
2323
}
2424

@@ -440,7 +440,7 @@ impl Deref for PyNumber<'_> {
440440
}
441441

442442
impl<'a> PyNumber<'a> {
443-
pub(crate) fn obj(self) -> &'a PyObject {
443+
pub(crate) const fn obj(self) -> &'a PyObject {
444444
self.0
445445
}
446446

‎vm/src/types/slot.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ impl PyComparisonOp {
11161116
}
11171117
}
11181118

1119-
pub fn operator_token(self) -> &'static str {
1119+
pub const fn operator_token(self) -> &'static str {
11201120
match self {
11211121
Self::Lt => "<",
11221122
Self::Le => "<=",

0 commit comments

Comments
 (0)