Using the method cache for the rest of the return statements in DboSource::name

This commit is contained in:
José Lorenzo Rodríguez 2010-02-23 10:09:11 -04:30
parent 753721c777
commit 6ae54fda8d

View file

@ -484,26 +484,26 @@ class DboSource extends DataSource {
} }
return $data; return $data;
} }
$cacheKey = crc32($data); $cacheKey = crc32($this->startQuote.$data.$this->endQuote);
if (isset($this->methodCache[__FUNCTION__][$cacheKey])) { if (isset($this->methodCache[__FUNCTION__][$cacheKey])) {
return $this->methodCache[__FUNCTION__][$cacheKey]; return $this->methodCache[__FUNCTION__][$cacheKey];
} }
$data = trim($data); $data = trim($data);
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
if (strpos($data, '.') === false) { // string if (strpos($data, '.') === false) { // string
return $this->startQuote . $data . $this->endQuote; return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . $data . $this->endQuote;
} }
$items = explode('.', $data); $items = explode('.', $data);
return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote; return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
} }
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.* if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data); return $this->methodCache[__FUNCTION__][$cacheKey] = $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
} }
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
return $matches[1] . '(' . $this->name($matches[2]) . ')'; return $this->methodCache[__FUNCTION__][$cacheKey] = $matches[1] . '(' . $this->name($matches[2]) . ')';
} }
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) { if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) {
return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3])); return $this->methodCache[__FUNCTION__][$cacheKey] = preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
} }
return $this->methodCache[__FUNCTION__][$cacheKey] = $data; return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
} }