From 75c807f31d8dd478b00420abee9183851b4b7239 Mon Sep 17 00:00:00 2001 From: kngwyu Date: Sat, 2 May 2020 23:38:12 +0900 Subject: [PATCH] Less borrow in GILPool::drop --- src/gil.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/gil.rs b/src/gil.rs index f57353ca..fa18f06b 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -244,16 +244,14 @@ impl Drop for GILPool { // while calling Py_DECREF we may cause other callbacks to run which will need to // register objects into the GILPool. let len = owned_objects.borrow().len(); - for i in self.owned_objects_start..len { - let ptr = owned_objects.borrow().get_unchecked(i).as_ptr(); - ffi::Py_DECREF(ptr); + if self.owned_objects_start < len { + let rest = owned_objects + .borrow_mut() + .split_off(self.owned_objects_start); + for obj in rest { + ffi::Py_DECREF(obj.as_ptr()); + } } - // If this assertion fails, something weird is going on where another GILPool that was - // created after this one has not yet been dropped. - debug_assert!(owned_objects.borrow().len() == len); - owned_objects - .borrow_mut() - .truncate(self.owned_objects_start); }); OWNED_ANYS.with(|owned_anys| owned_anys.borrow_mut().truncate(self.owned_anys_start));