cv
unread,Sep 14, 2009, 1:51:42 AM9/14/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to kiwiphp
我改了一下KiwiSystemCache::getClassFileMapping函数,效率似乎有一点点提升,代码感觉稍微要清晰点吧。
static public function getClassFileMapping($cacheKey, $directories)
{
if ('dev' == Kiwi::$envMode || !self::$opcodeCacheInstance || !
($mapping = self::$opcodeCacheInstance->get($cacheKey)))
{
while ($directories)
{
$currentDir = array_shift($directories);
if (is_dir($currentDir))
{
$dir = new DirectoryIterator($currentDir);
foreach ($dir as $fileinfo)
{
$file = $fileinfo->getFilename();
if (!$fileinfo->isDot () && '.svn' != $file)
{
$currentFile = $fileinfo->getPathname();
$extension = pathinfo($file, PATHINFO_EXTENSION);
if ($fileinfo->isFile () && ($extension == 'php' || $extension
== 'inc'))// we will judge the file extension, we only accept 'php'
and 'inc' file.
{
$currentFileContent = trim(file_get_contents($currentFile));
if(preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|
interface)\s+(\w+)(\s+(extends|implements)\s+(\w+))?\s*{~mi',
$currentFileContent, $classes) > 0)
{
foreach($classes[1] as $key => $class)
{
$mapping[$class] = $currentFile;
}
}
else
{
include($currentFile);
}
}
// if $currentFile is a directory, pass through the next loop.
else if($fileinfo->isDir ())
{
$directories[] = $currentFile . DIRECTORY_SEPARATOR;
}
}
}
}
}
if ('dev' != Kiwi::$envMode && self::$opcodeCacheInstance)
{
self::$opcodeCacheInstance->add($cacheKey, $mapping);
}
}
return $mapping;
}