1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Speed up deep checks by quite a bit

This commit is contained in:
Matthew Brown 2016-05-20 00:24:26 -04:00
parent 333caeaeaa
commit d258e0debd
2 changed files with 14 additions and 9 deletions

View File

@ -39,10 +39,12 @@ class FunctionChecker implements StatementsSource
{
if ($this->_function->stmts) {
if (ClassChecker::getThisClass() && $this instanceof ClassMethodChecker) {
$hash = md5($this->getMethodId() . json_encode($vars_in_scope) . ' ' . json_encode($vars_possibly_in_scope));
$hash = $this->getMethodId() . json_encode([$vars_in_scope, $vars_possibly_in_scope]);
// if we know that the function has no effects on vars, we don't bother checking
if (isset(self::$_no_effects_hashes[$hash])) {
list($vars_in_scope, $vars_possibly_in_scope) = self::$_no_effects_hashes[$hash];
return;
}
}
@ -104,11 +106,7 @@ class FunctionChecker implements StatementsSource
}
if (ClassChecker::getThisClass() && $this instanceof ClassMethodChecker) {
$new_hash = md5($this->getMethodId() . json_encode($vars_in_scope) . ' ' . json_encode($vars_possibly_in_scope));
if ($hash === $new_hash) {
self::$_no_effects_hashes[$hash] = true;
}
self::$_no_effects_hashes[$hash] = [$vars_in_scope, $vars_possibly_in_scope];
}
}
}

View File

@ -676,7 +676,9 @@ class StatementsChecker
$use_vars = [];
if (!$this->_is_static) {
$use_vars['this'] = ClassChecker::getThisClass() ?: $this->_absolute_class;
$use_vars['this'] = ClassChecker::getThisClass() && is_subclass_of(ClassChecker::getThisClass(), $this->_absolute_class) ?
ClassChecker::getThisClass() :
$this->_absolute_class;
}
foreach ($vars_in_scope as $var => $type) {
@ -1338,9 +1340,14 @@ class StatementsChecker
self::$_this_calls[$this_method_id][] = $stmt->name;
if (ClassChecker::getThisClass()) {
if (ClassChecker::getThisClass() &&
(
ClassChecker::getThisClass() === $this->_absolute_class ||
is_subclass_of(ClassChecker::getThisClass(), $this->_absolute_class) ||
trait_exists($this->_absolute_class)
)) {
$method_id = ClassChecker::getThisClass() . '::' . $stmt->name;
$method_id = $this->_absolute_class . '::' . $stmt->name;
$method_checker = ClassChecker::getMethodChecker($method_id);