Make performance of the class loader more constant across classes
parent
5ba147663d
commit
94175ce432
|
@ -49,7 +49,7 @@ class ClassLoader
|
|||
|
||||
public function getPrefixes()
|
||||
{
|
||||
return $this->prefixes;
|
||||
return call_user_func_array('array_merge', $this->prefixes);
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
|
@ -98,19 +98,20 @@ class ClassLoader
|
|||
|
||||
return;
|
||||
}
|
||||
if (!isset($this->prefixes[$prefix])) {
|
||||
$this->prefixes[$prefix] = (array) $paths;
|
||||
$first = substr($prefix, 0, 1);
|
||||
if (!isset($this->prefixes[$first][$prefix])) {
|
||||
$this->prefixes[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixes[$prefix] = array_merge(
|
||||
$this->prefixes[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixes[$prefix]
|
||||
$this->prefixes[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixes[$prefix] = array_merge(
|
||||
$this->prefixes[$prefix],
|
||||
$this->prefixes[$first][$prefix] = array_merge(
|
||||
$this->prefixes[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ class ClassLoader
|
|||
|
||||
return;
|
||||
}
|
||||
$this->prefixes[$prefix] = (array) $paths;
|
||||
$this->prefixes[substr($prefix, 0, 1)][$prefix] = (array) $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,7 +206,7 @@ class ClassLoader
|
|||
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
|
||||
$classPath = strtr(substr($class, 0, $pos), '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
$className = substr($class, $pos + 1);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
|
@ -213,9 +214,11 @@ class ClassLoader
|
|||
$className = $class;
|
||||
}
|
||||
|
||||
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
$classPath .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php';
|
||||
|
||||
foreach ($this->prefixes as $prefix => $dirs) {
|
||||
$first = substr($class, 0, 1);
|
||||
if (isset($this->prefixes[$first])) {
|
||||
foreach ($this->prefixes[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
|
||||
|
@ -224,6 +227,7 @@ class ClassLoader
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->fallbackDirs as $dir) {
|
||||
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
|
||||
|
|
Loading…
Reference in New Issue