Skip to content

Commit

Permalink
Improve performance of destructing objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rwols committed Aug 4, 2021
1 parent 26cbf1e commit 3db7eed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions zend/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion zend/classimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3db7eed

Please sign in to comment.