Skip to content

Commit 3db7eed

Browse files
committed
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.
1 parent 26cbf1e commit 3db7eed

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

zend/base.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ namespace Php {
1717
*/
1818
void Base::__destruct() const
1919
{
20-
// throw exception, so that the PHP-CPP library will check if the user
21-
// somehow registered an explicit __destruct method
22-
throw NotImplemented();
20+
// destroy the object by default
21+
zend_objects_destroy_object(_impl->php());
2322
}
2423

2524
/**

zend/classimpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,9 @@ void ClassImpl::destructObject(zend_object *object)
11301130
}
11311131
catch (const NotImplemented &exception)
11321132
{
1133-
// fallback on the default destructor call
1133+
// fallback on the default destructor call in case a derived object
1134+
// of Base throws this. The default implementation will call this
1135+
// function in any case.
11341136
zend_objects_destroy_object(object);
11351137
}
11361138
catch (Throwable &throwable)

0 commit comments

Comments
 (0)