From 41a976cc85ab36dc2df748b9d6900d77e76b2fa7 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau Date: Mon, 28 Feb 2022 14:58:24 +0100 Subject: code review: copy simplex tree c++ pointer in a factorized nogil function --- src/python/gudhi/simplex_tree.pyx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/python/gudhi') diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index 91e079aa..b8fabf78 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -54,11 +54,9 @@ cdef class SimplexTree: # The real cython constructor def __cinit__(self, other = None): - cdef SimplexTree ostr if other: if isinstance(other, SimplexTree): - ostr = other - self.thisptr = (new Simplex_tree_interface_full_featured(dereference(ostr.get_ptr()))) + self.thisptr = _get_copy_intptr(other) else: raise TypeError("`other` argument requires to be of type `SimplexTree`, or `None`.") else: @@ -90,12 +88,7 @@ cdef class SimplexTree: :func:`compute_persistence` on it even if you had already computed it in the original. """ stree = SimplexTree() - cdef Simplex_tree_interface_full_featured* stree_ptr - cdef Simplex_tree_interface_full_featured* self_ptr=self.get_ptr() - with nogil: - stree_ptr = new Simplex_tree_interface_full_featured(dereference(self_ptr)) - - stree.thisptr = (stree_ptr) + stree.thisptr = _get_copy_intptr(self) return stree def __deepcopy__(self): @@ -687,3 +680,6 @@ cdef class SimplexTree: :rtype: bool """ return dereference(self.get_ptr()) == dereference(other.get_ptr()) + +cdef intptr_t _get_copy_intptr(SimplexTree stree) nogil: + return (new Simplex_tree_interface_full_featured(dereference(stree.get_ptr()))) -- cgit v1.2.3