Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Intervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Intervals
*/
private static $intervalsCache = array();

/**
* @phpstan-var array<string, ConstraintInterface>
*/
private static $compactedCache = array();

/**
* @phpstan-var array<string, int>
*/
Expand All @@ -54,6 +59,7 @@ class Intervals
public static function clear()
{
self::$intervalsCache = array();
self::$compactedCache = array();
}

/**
Expand Down Expand Up @@ -142,6 +148,19 @@ public static function compactConstraint(ConstraintInterface $constraint)
return $constraint;
}

$key = (string) $constraint;
if (!isset(self::$compactedCache[$key])) {
self::$compactedCache[$key] = self::doCompactConstraint($constraint);
}

return self::$compactedCache[$key];
}

/**
* @return ConstraintInterface
*/
private static function doCompactConstraint(MultiConstraint $constraint)
{
$intervals = self::generateIntervals($constraint);
$constraints = array();
$hasNumericMatchAll = false;
Expand Down
Loading