Skip to content
Permalink
Browse files

Making the class loader check faster

  • Loading branch information...
jrbasso committed Jun 24, 2012
1 parent beb66e4 commit d7806fc7bcb37dfb994f81b4c1827584dc245d53
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/Cake/Core/ClassLoader.php
@@ -39,6 +39,13 @@ class ClassLoader {
*/
protected $namespace;
/**
* Store the namespace length for performance
*
* @var integer
*/
protected $namespaceLength;
/**
* Path with the classes
*
@@ -60,6 +67,7 @@ class ClassLoader {
*/
public function __construct($ns = null, $includePath = null) {
$this->namespace = rtrim($ns, $this->namespaceSeparator) . $this->namespaceSeparator;
$this->namespaceLength = strlen($this->namespace);
$this->includePath = $includePath;
}
@@ -145,7 +153,7 @@ public function unregister() {
* @return boolean
*/
public function loadClass($className) {
if (strpos($className, $this->namespace) === 0) {
if (substr($className, 0, $this->namespaceLength) === $this->namespace) {
$path = $this->includePath . DS . str_replace($this->namespaceSeparator, DS, $className) . $this->fileExtension;
if (!file_exists($path)) {
return false;

0 comments on commit d7806fc

Please sign in to comment.
You can’t perform that action at this time.