From 3db7eed7a9173dd158c477ad2eea0cea47c6c3d1 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Wed, 4 Aug 2021 10:35:08 +0200 Subject: [PATCH] Improve performance of destructing objects We used to throw a NotImplemented exception, but this causes the c++ runtime to allocate on the heap. We can call zend_objects_destroy_object directly in the Php::Base::__destroy method instead. If someone overrides this method, then zend_objects_destroy_object will not be called, which is the behavior we had before as well. --- zend/base.cpp | 5 ++--- zend/classimpl.cpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/zend/base.cpp b/zend/base.cpp index 4cb3cd85..ed6fe3bc 100644 --- a/zend/base.cpp +++ b/zend/base.cpp @@ -17,9 +17,8 @@ namespace Php { */ void Base::__destruct() const { - // throw exception, so that the PHP-CPP library will check if the user - // somehow registered an explicit __destruct method - throw NotImplemented(); + // destroy the object by default + zend_objects_destroy_object(_impl->php()); } /** diff --git a/zend/classimpl.cpp b/zend/classimpl.cpp index 6ff96c02..def3e706 100644 --- a/zend/classimpl.cpp +++ b/zend/classimpl.cpp @@ -1130,7 +1130,9 @@ void ClassImpl::destructObject(zend_object *object) } catch (const NotImplemented &exception) { - // fallback on the default destructor call + // fallback on the default destructor call in case a derived object + // of Base throws this. The default implementation will call this + // function in any case. zend_objects_destroy_object(object); } catch (Throwable &throwable)