Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor performance optimization for lookups of `ArrayCollection#contains()` #241

Merged
merged 1 commit into from

3 participants

Marco Pivetta doctrinebot Guilherme Blanco
Marco Pivetta
Owner

No description provided.

doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DCOM-159

Marco Pivetta
Owner

Weird that this was patched for the opposite direction before O_o The previous commit reverting in_array was probably only considering empty collections. With larger collections, performance degrades a lot with foreach (even for just 100 elements)

Guilherme Blanco guilhermeblanco merged commit bc6bc47 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 8, 2013
  1. Marco Pivetta
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 7 deletions.
  1. +1 −7 lib/Doctrine/Common/Collections/ArrayCollection.php
8 lib/Doctrine/Common/Collections/ArrayCollection.php
View
@@ -229,13 +229,7 @@ public function containsKey($key)
*/
public function contains($element)
{
- foreach ($this->_elements as $collectionElement) {
- if ($element === $collectionElement) {
- return true;
- }
- }
-
- return false;
+ return in_array($element, $this->_elements, true);
}
/**
Something went wrong with that request. Please try again.