constify a bunch of methods

This commit is contained in:
ShaharNaveh authored and Jeong, YunWon committed 2025-06-22 09:33:10 +09:00
1 parent 55740b2277
commit e6f5b6ad1a
7 files changed
+19 -9

No files matched your search

+6 -2
View File
@@ -302,12 +302,14 @@ pub trait FromArgOptional {
type Inner: TryFromObject;
fn from_inner(x: Self::Inner) -> Self;
}
impl<T: TryFromObject> FromArgOptional for OptionalArg<T> {
type Inner = T;
fn from_inner(x: T) -> Self {
Self::Present(x)
}
}
impl<T: TryFromObject> FromArgOptional for T {
type Inner = Self;
fn from_inner(x: Self) -> Self {
@@ -342,7 +344,7 @@ where
}
impl<T> KwArgs<T> {
pub fn new(map: IndexMap<String, T>) -> Self {
pub const fn new(map: IndexMap<String, T>) -> Self {
KwArgs(map)
}
@@ -354,11 +356,13 @@ impl<T> KwArgs<T> {
self.0.is_empty()
}
}
impl<T> FromIterator<(String, T)> for KwArgs<T> {
fn from_iter<I: IntoIterator<Item = (String, T)>>(iter: I) -> Self {
KwArgs(iter.into_iter().collect())
}
}
impl<T> Default for KwArgs<T> {
fn default() -> Self {
KwArgs(IndexMap::new())
@@ -408,7 +412,7 @@ where
}
impl<T> PosArgs<T> {
pub fn new(args: Vec<T>) -> Self {
pub const fn new(args: Vec<T>) -> Self {
Self(args)
}
+4 -4
View File
@@ -51,11 +51,11 @@ impl ArgBytesLike {
f(&self.borrow_buf())
}
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.0.desc.len
}
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
@@ -103,11 +103,11 @@ impl ArgMemoryBuffer {
f(&mut self.borrow_buf_mut())
}
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.0.desc.len
}
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
}
+1
View File
@@ -491,6 +491,7 @@ pub struct PyObject(PyInner<Erased>);
impl Deref for PyObjectRef {
type Target = PyObject;
#[inline(always)]
fn deref(&self) -> &PyObject {
unsafe { self.ptr.as_ref() }
+4
View File
@@ -47,6 +47,7 @@ where
fmt::Display::fmt(&**self, f)
}
}
impl<T: fmt::Display> fmt::Display for Py<T>
where
T: PyObjectPayload + fmt::Display,
@@ -72,6 +73,7 @@ impl<T: PyPayload> PyExact<T> {
impl<T: PyPayload> Deref for PyExact<T> {
type Target = Py<T>;
#[inline(always)]
fn deref(&self) -> &Py<T> {
&self.inner
@@ -108,6 +110,7 @@ impl<T: PyObjectPayload> AsRef<Py<T>> for PyExact<T> {
impl<T: PyPayload> std::borrow::ToOwned for PyExact<T> {
type Owned = PyRefExact<T>;
fn to_owned(&self) -> Self::Owned {
let owned = self.inner.to_owned();
unsafe { PyRefExact::new_unchecked(owned) }
@@ -181,6 +184,7 @@ impl<T: PyPayload> TryFromObject for PyRefExact<T> {
impl<T: PyPayload> Deref for PyRefExact<T> {
type Target = PyExact<T>;
#[inline(always)]
fn deref(&self) -> &PyExact<T> {
unsafe { PyExact::ref_unchecked(self.inner.deref()) }
+1
View File
@@ -158,6 +158,7 @@ unsafe impl<A: Traverse> Traverse for (A,) {
self.0.traverse(tracer_fn);
}
}
trace_tuple!((A, 0), (B, 1));
trace_tuple!((A, 0), (B, 1), (C, 2));
trace_tuple!((A, 0), (B, 1), (C, 2), (D, 3));
+2 -2
View File
@@ -18,7 +18,7 @@ pub type PyNumberTernaryFunc = fn(&PyObject, &PyObject, &PyObject, &VirtualMachi
impl PyObject {
#[inline]
pub fn to_number(&self) -> PyNumber<'_> {
pub const fn to_number(&self) -> PyNumber<'_> {
PyNumber(self)
}
@@ -440,7 +440,7 @@ impl Deref for PyNumber<'_> {
}
impl<'a> PyNumber<'a> {
pub(crate) fn obj(self) -> &'a PyObject {
pub(crate) const fn obj(self) -> &'a PyObject {
self.0
}
+1 -1
View File
@@ -1116,7 +1116,7 @@ impl PyComparisonOp {
}
}
pub fn operator_token(self) -> &'static str {
pub const fn operator_token(self) -> &'static str {
match self {
Self::Lt => "<",
Self::Le => "<=",