Fix performance issue of cloned instances

I noted a performance issue using TCPDF when doing a lot of clones of the instance, it's caused by the destructor being called multiple times to cleanup things that already have been cleaned
This checks if the files have already been cleaned before redoing an expensive filesystem operation again (glob)
This commit is contained in:
Adrien Foulon 2019-03-22 12:53:16 +01:00 committed by GitHub
parent 756908329d
commit e91887e463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7737,6 +7737,7 @@ class TCPDF {
return '';
}
protected static $cleaned_ids = array();
/**
* Unset all class variables except the following critical variables.
* @param $destroyall (boolean) if true destroys all class variables, otherwise preserves critical variables.
@ -7749,7 +7750,11 @@ class TCPDF {
if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
mb_internal_encoding($this->internal_encoding);
}
if (isset(self::$cleaned_ids[$this->file_id])) {
$destroyall = false;
}
if ($destroyall AND !$preserve_objcopy) {
self::$cleaned_ids[$this->file_id] = true;
// remove all temporary files
$tmpfiles = glob(K_PATH_CACHE.'__tcpdf_'.$this->file_id.'_*');
if (!empty($tmpfiles)) {