Merge remote-tracking branch 'origin/support/3.2' into develop

This commit is contained in:
lenaick.moreira
2026-03-02 10:56:31 +01:00
123 changed files with 2898 additions and 2149 deletions

View File

@@ -26,6 +26,8 @@ use Symfony\Component\CssSelector\XPath\Translator;
*/
class CssSelectorConverter
{
public static int $maxCachedItems = 1024;
private Translator $translator;
private array $cache;
@@ -62,6 +64,21 @@ class CssSelectorConverter
*/
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
{
return $this->cache[$prefix][$cssExpr] ??= $this->translator->cssToXPath($cssExpr, $prefix);
$cacheKey = $prefix."\0".$cssExpr;
if (isset($this->cache[$cacheKey])) {
// Move the item last in cache (LRU)
$value = $this->cache[$cacheKey];
unset($this->cache[$cacheKey]);
return $this->cache[$cacheKey] = $value;
}
if (\count($this->cache) >= self::$maxCachedItems) {
// Evict the oldest entry
unset($this->cache[array_key_first($this->cache)]);
}
return $this->cache[$cacheKey] = $this->translator->cssToXPath($cssExpr, $prefix);
}
}