← All changes
|
includes/sdk/google/ramsey/collection/src/AbstractSet.php
+10
-10
1.0.3
→
1.4.1
View file →
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> |
| 10 | 10 | * @license http://opensource.org/licenses/MIT MIT |
| 11 | 11 | */ |
| 12 | 12 | declare (strict_types=1); |
| 13 | -namespace Dudlewebs\WPMCS\Ramsey\Collection; | |
| 13 | +namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection; | |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * This class contains the basic implementation of a collection that does not |
| 17 | 17 | * allow duplicated values (a set), to minimize the effort required to implement |
| @@ -21,22 +21,22 @@ | ||
| 21 | 21 | * @extends AbstractCollection<T> |
| 22 | 22 | */ |
| 23 | 23 | abstract class AbstractSet extends AbstractCollection |
| 24 | 24 | { |
| 25 | - /** | |
| 26 | - * @inheritDoc | |
| 27 | - */ | |
| 28 | - public function add($element): bool | |
| 25 | + public function add(mixed $element) : bool | |
| 29 | 26 | { |
| 30 | 27 | if ($this->contains($element)) { |
| 31 | 28 | return \false; |
| 32 | 29 | } |
| 33 | - return parent::add($element); | |
| 30 | + // Call offsetSet() on the parent instead of add(), since calling | |
| 31 | + // parent::add() will invoke $this->offsetSet(), which will call | |
| 32 | + // $this->contains() a second time. This can cause performance issues | |
| 33 | + // with extremely large collections. For more information, see | |
| 34 | + // https://github.com/ramsey/collection/issues/68. | |
| 35 | + parent::offsetSet(null, $element); | |
| 36 | + return \true; | |
| 34 | 37 | } |
| 35 | - /** | |
| 36 | - * @inheritDoc | |
| 37 | - */ | |
| 38 | - public function offsetSet($offset, $value): void | |
| 38 | + public function offsetSet(mixed $offset, mixed $value) : void | |
| 39 | 39 | { |
| 40 | 40 | if ($this->contains($value)) { |
| 41 | 41 | return; |
| 42 | 42 | } |