bug #14012 [DomCrawler] Improve namespace discovery performance (jakzal)

This PR was merged into the 2.6 branch.

Discussion
----------

[DomCrawler] Improve namespace discovery performance

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12298
| License       | MIT
| Doc PR        | -

Before this quick-fix, xpath axes like `child::*` or `descendant-or-self::*` were considered namespaces. As a result, far too many xpath queries were being executed during namespace discovery.

Here's a full blackfire before/after comparision of @salaman's script:  https://blackfire.io/profiles/compare/a80b9e77-8e55-45d3-a348-7d34a51053b6/graph

![domcrawler-xpath-query](https://cloud.githubusercontent.com/assets/190447/6767384/ba93c57a-d024-11e4-84e1-e58dd7527f03.png)

Commits
-------

b6af002 [DomCrawler] Improve namespace discovery performance
This commit is contained in:
Fabien Potencier 2015-03-23 07:58:55 +01:00
commit bd7788a106

View File

@ -1027,7 +1027,7 @@ class Crawler extends \SplObjectStorage
*/
private function findNamespacePrefixes($xpath)
{
if (preg_match_all('/(?P<prefix>[a-z_][a-z_0-9\-\.]*):[^"\/]/i', $xpath, $matches)) {
if (preg_match_all('/(?P<prefix>[a-z_][a-z_0-9\-\.]*):[^"\/:]/i', $xpath, $matches)) {
return array_unique($matches['prefix']);
}