1
0
mirror of synced 2025-02-02 13:31:45 +03:00

#6613 #6614 #6616 minor performance optimisations around the new restoreNewObjectsInDirtyCollection implementation

This commit is contained in:
Marco Pivetta 2017-08-11 21:14:05 +02:00
parent ab63628960
commit 5cacb6e14f
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629

View File

@ -712,13 +712,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;
}
}
}