浏览代码

merged branch stof/mapping_driver_optimization (PR #1729)

Commits
-------

5d17b92 [DoctrineBridge] Optimized the mapping drivers

Discussion
----------

[DoctrineBridge] Optimized the mapping drivers

This avoids loading all mappings when calling ``isTransient`` as it adds an overhead.

---------------------------------------------------------------------------

by beberlei at 2011/07/18 11:35:36 -0700

Its much better than the original one.

---------------------------------------------------------------------------

by stof at 2011/07/18 11:53:09 -0700

For the mapping defined in a specific class, this simply checks if the file exists (like Doctrine's implementation) but reusing the other method to keep the code DRY.
There is still an overhead when using a global mapping file but I don't see a way to avoid loading the file.
Fabien Potencier 14 年之前
父节点
当前提交
69a4af8868

+ 16 - 1
src/Symfony/Bridge/Doctrine/Mapping/Driver/XmlDriver.php

@@ -48,7 +48,22 @@ class XmlDriver extends BaseXmlDriver
 
     public function isTransient($className)
     {
-        return !in_array($className, $this->getAllClassNames());
+        if (null === $this->_classCache) {
+            $this->initialize();
+        }
+
+        // The mapping is defined in the global mapping file
+        if (isset($this->_classCache[$className])) {
+            return false;
+        }
+
+        try {
+            $this->_findMappingFile($className);
+
+            return false;
+        } catch (MappingException $e) {
+            return true;
+        }
     }
 
     public function getAllClassNames()

+ 16 - 1
src/Symfony/Bridge/Doctrine/Mapping/Driver/YamlDriver.php

@@ -48,7 +48,22 @@ class YamlDriver extends BaseYamlDriver
 
     public function isTransient($className)
     {
-        return !in_array($className, $this->getAllClassNames());
+        if (null === $this->_classCache) {
+            $this->initialize();
+        }
+
+        // The mapping is defined in the global mapping file
+        if (isset($this->_classCache[$className])) {
+            return false;
+        }
+
+        try {
+            $this->_findMappingFile($className);
+
+            return false;
+        } catch (MappingException $e) {
+            return true;
+        }
     }
 
     public function getAllClassNames()