File tree 2 files changed +7
-2
lines changed
src/Symfony/Component/CssSelector 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change 27
27
class CssSelectorConverter
28
28
{
29
29
private $ translator ;
30
+ private static $ cache = [];
30
31
31
32
/**
32
33
* @param bool $html Whether HTML support should be enabled. Disable it for XML documents
@@ -57,6 +58,10 @@ public function __construct(bool $html = true)
57
58
*/
58
59
public function toXPath (string $ cssExpr , string $ prefix = 'descendant-or-self:: ' )
59
60
{
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 );
61
66
}
62
67
}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function testCssToXPathXml()
32
32
{
33
33
$ converter = new CssSelectorConverter (false );
34
34
35
- $ this ->assertEquals ('descendant-or-self::H1 ' , $ converter ->toXPath ('H1 ' ));
35
+ $ this ->assertEquals ('descendant-or-self::h1 ' , $ converter ->toXPath ('H1 ' ));
36
36
}
37
37
38
38
public function testParseExceptions ()
You can’t perform that action at this time.
0 commit comments