From 0d7a641aa9642ccf4b745f496d9e441c4ae61aa8 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 15 Dec 2011 18:35:48 +0100 Subject: [PATCH] lazily calculate control flow in ScopeImpl --- .../dataflow/scope/impl/ScopeImpl.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java index 3a2d2da2ff73..b4fff8178244 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/impl/ScopeImpl.java @@ -23,8 +23,8 @@ import java.util.*; * @author oleg */ public class ScopeImpl implements Scope { - private final Instruction[] myFlow; - private List> myCachedScopeVariables; + private volatile Instruction[] myFlow; + private volatile List> myCachedScopeVariables; private Set myGlobals; private Set myNonlocals; private final ScopeOwner myFlowOwner; @@ -33,7 +33,12 @@ public class ScopeImpl implements Scope { public ScopeImpl(final ScopeOwner flowOwner) { myFlowOwner = flowOwner; - myFlow = ControlFlowCache.getControlFlow(flowOwner).getInstructions(); + } + + private synchronized void computeFlow() { + if (myFlow == null) { + myFlow = ControlFlowCache.getControlFlow(myFlowOwner).getInstructions(); + } } @NotNull @@ -62,7 +67,8 @@ public class ScopeImpl implements Scope { return null; } - public List> computeScopeVariables() throws DFALimitExceededException { + private synchronized List> computeScopeVariables() throws DFALimitExceededException { + computeFlow(); if (myCachedScopeVariables == null) { final PyReachingDefsDfaInstance dfaInstance = new PyReachingDefsDfaInstance(); final PyReachingDefsSemilattice semilattice = new PyReachingDefsSemilattice(); @@ -104,6 +110,7 @@ public class ScopeImpl implements Scope { } private Set computeAllNames() { + computeFlow(); final Set names = new HashSet(); for (Instruction instruction : myFlow) { if (instruction instanceof ReadWriteInstruction && ((ReadWriteInstruction)instruction).getAccess().isWriteAccess()){