From cca16ff597743a78ddad69e3ecf56db28b205680 Mon Sep 17 00:00:00 2001 From: Matthew Constable Date: Sat, 9 Feb 2019 21:38:11 +0000 Subject: [PATCH] Simplify calling __hash__ method --- vm/src/obj/objset.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index 249004f85..9e6166a91 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -9,6 +9,7 @@ use super::super::vm::VirtualMachine; use super::objbool; use super::objiter; use super::objstr; +use super::objint; use super::objtype; use num_bigint::BigInt; use std::collections::HashMap; @@ -32,20 +33,11 @@ fn perform_action_with_hash( &PyObjectRef, ) -> PyResult, ) -> PyResult { - let hash_result: PyResult = vm.call_method(item, "__hash__", vec![]); - match hash_result { - Ok(hash_object) => { - let hash = hash_object.borrow(); - match hash.payload { - PyObjectPayload::Integer { ref value } => { - let key = value.clone(); - f(vm, elements, key, item) - } - _ => Err(vm.new_type_error(format!("__hash__ method should return an integer"))), - } - } - Err(error) => Err(error), - } + let hash: PyObjectRef = vm.call_method(item, "__hash__", vec![])?; + + let hash_value = objint::get_value(&hash); + let key = hash_value.clone(); + f(vm, elements, key, item) } fn insert_into_set(