Skip to content

Commit

Permalink
Improve performance of Types (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd authored Nov 21, 2023
1 parent 733c5f2 commit 30bc236
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/core/etl/src/Flow/ETL/PHP/Type/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ final class Types implements \Countable
{
private readonly ?Type $first;

private readonly array $types;
/**
* @var string[]
*/
private array $types;

public function __construct(Type ...$types)
{
$this->types = \array_map(
fn (string $type) : Type => \unserialize($type),
\array_unique(
\array_map(fn (Type $type) : string => \serialize($type), $types)
)
$this->types = \array_unique(
\array_map(fn (Type $type) : string => $type->toString(), $types)
);
$this->first = $this->types[0] ?? null;
$this->first = $types[0] ?? null;
}

public function count() : int
Expand All @@ -33,14 +33,16 @@ public function first() : ?Type

public function without(Type ...$types) : self
{
return new self(...\array_filter($this->types, function (Type $type) use ($types) : bool {
$this->types = \array_filter($this->types, function (string $type) use ($types) : bool {
foreach ($types as $withoutType) {
if ($type->isEqual($withoutType)) {
if ($type === $withoutType->toString()) {
return false;
}
}

return true;
}));
});

return $this;
}
}

0 comments on commit 30bc236

Please sign in to comment.