10000 [CssSelector] Added cache on top of CssSelectorConverter · symfony/symfony@d905643 · GitHub
[go: up one dir, main page]

Skip to content

Commit d905643

Browse files
committed
[CssSelector] Added cache on top of CssSelectorConverter
1 parent ddc0169 commit d905643

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Symfony/Component/CssSelector/CssSelectorConverter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class CssSelectorConverter
2828
{
2929
private $translator;
30+
private static $cache = [];
3031

3132
/**
3233
* @param bool $html Whether HTML support should be enabled. Disable it for XML documents
@@ -57,6 +58,10 @@ public function __construct(bool $html = true)
5758
*/
5859
public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::')
5960
{
60-
return $this->translator->cssToXPath($cssExpr, $prefix);
61+
if (self::$cache[$prefix][$cssExpr] ?? false) {
62+
return self::$cache[$prefix][$cssExpr];
63+
}
64+
65+
return self::$cache[$prefix][$cssExpr] = $this->translator->cssToXPath($cssExpr, $prefix);
6166
}
6267
}

src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testCssToXPathXml()
3232
{
3333
$converter = new CssSelectorConverter(false);
3434

35-
$this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));
35+
$this->assertEquals('descendant-or-self::h1', $converter->toXPath('H1'));
3636
}
3737

3838
public function testParseExceptions()

0 commit comments

Comments
 (0)
0