Merge pull request #4548 from youknowone/hash-tuple

Prepare to implement hash for tuple
This commit is contained in:
Jeong YunWon
2023-02-23 02:08:13 +09:00
committed by GitHub
2 changed files with 14 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
use super::{PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef};
use crate::atomic_func;
use crate::common::hash::PyHash;
use super::{
builtins_iter, tuple::tuple_hash, PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef,
};
use crate::{
builtins::builtins_iter,
atomic_func,
class::PyClassImpl,
common::hash::PyHash,
function::{FuncArgs, OptionalArg, PyComparisonValue},
protocol::{PyIterReturn, PyMappingMethods, PySequenceMethods},
types::{
@@ -442,7 +443,7 @@ impl Hashable for PyRange {
zelf.step().into(),
]
};
crate::utils::hash_iter(elements.iter(), vm)
tuple_hash(&elements, vm)
}
}

View File

@@ -1,9 +1,9 @@
use once_cell::sync::Lazy;
use super::{PositionIterInternal, PyGenericAlias, PyType, PyTypeRef};
use crate::atomic_func;
use crate::common::{hash::PyHash, lock::PyMutex};
use crate::{
atomic_func,
class::PyClassImpl,
convert::{ToPyObject, TransmuteFromObject},
function::{OptionalArg, PyArithmeticValue, PyComparisonValue},
@@ -372,7 +372,7 @@ impl AsSequence for PyTuple {
impl Hashable for PyTuple {
#[inline]
fn hash(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyHash> {
crate::utils::hash_iter(zelf.elements.iter(), vm)
tuple_hash(zelf.as_slice(), vm)
}
}
@@ -523,3 +523,9 @@ impl<T: TransmuteFromObject> ToPyObject for PyTupleTyped<T> {
self.tuple.into()
}
}
pub(super) fn tuple_hash(elements: &[PyObjectRef], vm: &VirtualMachine) -> PyResult<PyHash> {
// TODO: See #3460 for the correct implementation.
// https://github.com/RustPython/RustPython/pull/3460
crate::utils::hash_iter(elements.iter(), vm)
}