From 004ac518695da8a0194d1dbd2ba00574a6027a12 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 11 Aug 2017 21:14:05 +0200 Subject: [PATCH] #6613 #6614 #6616 minor performance optimisations around the new `restoreNewObjectsInDirtyCollection` implementation --- lib/Doctrine/ORM/PersistentCollection.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 1ce3e495b..9abea4f22 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -720,13 +720,15 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec private function restoreNewObjectsInDirtyCollection(array $newObjects) { $loadedObjects = $this->collection->toArray(); - $newObjectsByOid = array_combine(array_map('spl_object_hash', $newObjects), $newObjects); - $loadedObjectsByOid = array_combine(array_map('spl_object_hash', $loadedObjects), $loadedObjects); - $newObjectsThatWereNotLoaded = array_diff_key($newObjectsByOid, $loadedObjectsByOid); + $newObjectsByOid = \array_combine(\array_map('spl_object_hash', $newObjects), $newObjects); + $loadedObjectsByOid = \array_combine(\array_map('spl_object_hash', $loadedObjects), $loadedObjects); + $newObjectsThatWereNotLoaded = \array_diff_key($newObjectsByOid, $loadedObjectsByOid); - // Reattach NEW objects added through add(), if any. - array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); + if ($newObjectsThatWereNotLoaded) { + // Reattach NEW objects added through add(), if any. + \array_walk($newObjectsThatWereNotLoaded, [$this->collection, 'add']); - $this->isDirty = (bool) $newObjectsThatWereNotLoaded; + $this->isDirty = true; + } } }