summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsefftinge2009-01-20 08:48:33 (EST)
committersefftinge2009-01-20 08:48:33 (EST)
commit9259136b7492f6ec88b2f8df9814762b75687243 (patch)
tree1ba7cd6929c4c5358f2ecc40cafcedccedb89eda
parentdc29854fcb2d4183daec0e0c96d4b7d942f19231 (diff)
downloadorg.eclipse.xpand-9259136b7492f6ec88b2f8df9814762b75687243.zip
org.eclipse.xpand-9259136b7492f6ec88b2f8df9814762b75687243.tar.gz
org.eclipse.xpand-9259136b7492f6ec88b2f8df9814762b75687243.tar.bz2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=261629
-rw-r--r--plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/XpandPluginExecutionContext.java2
-rw-r--r--plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java8
-rw-r--r--plugins/org.eclipse.xtend.shared.ui/src/org/eclipse/xtend/shared/ui/expression/PluginExecutionContextImpl.java2
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/Performance.ext52
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/PerformanceTest.java30
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java2
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java40
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/Resource.java2
8 files changed, 121 insertions, 17 deletions
diff --git a/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/XpandPluginExecutionContext.java b/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/XpandPluginExecutionContext.java
index cf673fe..5e96382 100644
--- a/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/XpandPluginExecutionContext.java
+++ b/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/XpandPluginExecutionContext.java
@@ -36,7 +36,7 @@ public class XpandPluginExecutionContext extends org.eclipse.xpand2.XpandExecuti
TypeSystemImpl typeSystem, Map<String, Variable> vars, Map<String, Variable> globalVars, Output output,
ProtectedRegionResolver prs, ProgressMonitor monitor, IXtendXpandProject xp) {
super(resourceManager, currentResource, typeSystem, vars, globalVars, output, prs, monitor, null, null, null,
- null, null);
+ null, null, null);
this.project = xp;
}
diff --git a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
index 9e18841..6fd92b8 100644
--- a/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
+++ b/plugins/org.eclipse.xpand/src/org/eclipse/xpand2/XpandExecutionContextImpl.java
@@ -33,6 +33,8 @@ import org.eclipse.internal.xpand2.pr.ProtectedRegionResolver;
import org.eclipse.internal.xpand2.type.XpandTypesMetaModel;
import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
import org.eclipse.internal.xtend.type.baseimpl.PolymorphicResolver;
+import org.eclipse.internal.xtend.util.Cache;
+import org.eclipse.internal.xtend.util.Triplet;
import org.eclipse.internal.xtend.xtend.ast.Around;
import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.xpand2.output.Output;
@@ -92,8 +94,8 @@ public class XpandExecutionContextImpl extends ExecutionContextImpl implements X
protected XpandExecutionContextImpl (ResourceManager resourceManager, Resource currentResource, TypeSystemImpl typeSystem, Map<String, Variable> vars,
- Map<String, Variable> globalVars, Output output, ProtectedRegionResolver protectedRegionResolver, ProgressMonitor monitor, ExceptionHandler exceptionHandler,List<Around> advices, NullEvaluationHandler nullEvaluationHandler, Map<Resource, Set<Extension>> allExtensionsPerResource, Callback callback) {
- super (resourceManager, currentResource, typeSystem, vars, globalVars, monitor, exceptionHandler,advices, nullEvaluationHandler,allExtensionsPerResource, callback);
+ Map<String, Variable> globalVars, Output output, ProtectedRegionResolver protectedRegionResolver, ProgressMonitor monitor, ExceptionHandler exceptionHandler,List<Around> advices, NullEvaluationHandler nullEvaluationHandler, Map<Resource, Set<Extension>> allExtensionsPerResource, Callback callback, Cache<Triplet<Resource,String,List<Type>>,Extension> extensionsForNameAndTypesCache) {
+ super (resourceManager, currentResource, typeSystem, vars, globalVars, monitor, exceptionHandler,advices, nullEvaluationHandler,allExtensionsPerResource, callback,extensionsForNameAndTypesCache);
registerMetaModel(new XpandTypesMetaModel(this));
this.output = output;
this.protectedRegionResolver = protectedRegionResolver;
@@ -105,7 +107,7 @@ public class XpandExecutionContextImpl extends ExecutionContextImpl implements X
@Override
public XpandExecutionContextImpl cloneContext() {
final XpandExecutionContextImpl result = new XpandExecutionContextImpl (resourceManager, currentResource(), typeSystem, getVisibleVariables(), getGlobalVariables(), output,
- protectedRegionResolver, getMonitor(), exceptionHandler,registeredExtensionAdvices, nullEvaluationHandler,allExtensionsPerResource, callback);
+ protectedRegionResolver, getMonitor(), exceptionHandler,registeredExtensionAdvices, nullEvaluationHandler,allExtensionsPerResource, callback,this.extensionsForNameAndTypesCache);
result.registeredAdvices.addAll(registeredAdvices); //todo: [aha] before I refactored, there was an assignment in this place. Is this modification correct?
return result;
}
diff --git a/plugins/org.eclipse.xtend.shared.ui/src/org/eclipse/xtend/shared/ui/expression/PluginExecutionContextImpl.java b/plugins/org.eclipse.xtend.shared.ui/src/org/eclipse/xtend/shared/ui/expression/PluginExecutionContextImpl.java
index 283ed37..5e9dd27 100644
--- a/plugins/org.eclipse.xtend.shared.ui/src/org/eclipse/xtend/shared/ui/expression/PluginExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend.shared.ui/src/org/eclipse/xtend/shared/ui/expression/PluginExecutionContextImpl.java
@@ -33,7 +33,7 @@ public class PluginExecutionContextImpl extends ExecutionContextImpl implements
protected PluginExecutionContextImpl(ResourceManager resourceManager, Resource currentResource,
TypeSystemImpl typeSystem, Map<String, Variable> vars, Map<String, Variable> globalVars,
IXtendXpandProject xp) {
- super(resourceManager, currentResource, typeSystem, vars, globalVars, null, null, null, null, null, null);
+ super(resourceManager, currentResource, typeSystem, vars, globalVars, null, null, null, null, null, null,null);
project = xp;
}
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/Performance.ext b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/Performance.ext
new file mode 100644
index 0000000..202d56a
--- /dev/null
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/Performance.ext
@@ -0,0 +1,52 @@
+
+
+doStuff(List[String] s) :
+ s.collect(e|e.doStuff());
+
+doStuff(String s) :
+ s;
+
+doStuff(Object s) :
+ s;
+
+other1(Object this) :
+ "1-Object";
+
+other2(Object this) :
+ "2-Object";
+
+other3(Object this) :
+ "3-Object";
+
+other4(Object this) :
+ "4-Object";
+
+other5(Object this) :
+ "4-Object";
+
+other6(Object this) :
+ "4-Object";
+
+other7(Object this) :
+ "4-Object";
+
+other8(Object this) :
+ "4-Object";
+
+other9(Object this) :
+ "4-Object";
+
+other10(Object this) :
+ "4-Object";
+
+other11(Object this) :
+ "4-Object";
+
+other12(Object this) :
+ "4-Object";
+
+other13(Object this) :
+ "4-Object";
+
+other14(Object this) :
+ "4-Object"; \ No newline at end of file
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/PerformanceTest.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/PerformanceTest.java
new file mode 100644
index 0000000..2448810
--- /dev/null
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/PerformanceTest.java
@@ -0,0 +1,30 @@
+package org.eclipse.xtend;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class PerformanceTest extends TestCase {
+ @SuppressWarnings("unchecked")
+ public void testPerformance() throws Exception {
+ final XtendFacade f = XtendFacade.create("org::eclipse::xtend::Performance");
+
+ List<Object> strings = new ArrayList<Object>();
+
+ for (int i = 0; i < 200000; i++) {
+ if (i%2==0) {
+ strings.add(i);
+ } else {
+ strings.add("string"+i);
+ }
+ }
+ long before = System.currentTimeMillis();
+ List<Object> result = (List<Object>) f.call("doStuff", new Object[] { strings });
+ long after = System.currentTimeMillis();
+ long time = after-before;
+ System.out.println(time);
+ assertTrue(time<9000);
+ assertEquals(strings,result);
+ }
+}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
index 15c8fbb..2bedafa 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/AbstractExpressionsUsingWorkflowComponent.java
@@ -122,7 +122,7 @@ public abstract class AbstractExpressionsUsingWorkflowComponent extends Abstract
final ExecutionContextImpl executionContext = new ExecutionContextImpl(getResourceManager(), null,
new TypeSystemImpl(), new HashMap<String, Variable>(), getGlobalVars(ctx), null, exceptionHandler,
- null, getNullEvaluationHandler(), null, callback);
+ null, getNullEvaluationHandler(), null, callback,null);
for (MetaModel mm : metaModels) {
executionContext.registerMetaModel(mm);
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
index 6069c7c..3b18c01 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/ExecutionContextImpl.java
@@ -29,6 +29,8 @@ import org.eclipse.internal.xtend.expression.ast.Identifier;
import org.eclipse.internal.xtend.expression.ast.SyntaxElement;
import org.eclipse.internal.xtend.type.baseimpl.PolymorphicResolver;
import org.eclipse.internal.xtend.type.baseimpl.TypesComparator;
+import org.eclipse.internal.xtend.util.Cache;
+import org.eclipse.internal.xtend.util.Triplet;
import org.eclipse.internal.xtend.xtend.XtendFile;
import org.eclipse.internal.xtend.xtend.ast.Around;
import org.eclipse.internal.xtend.xtend.ast.Extension;
@@ -82,30 +84,32 @@ public class ExecutionContextImpl implements ExecutionContext {
public ExecutionContextImpl(Map<String, Variable> globalVars) {
this(new ResourceManagerDefaultImpl(), null, new TypeSystemImpl(), new HashMap<String, Variable>(), globalVars,
- null, null, null, null, null, null);
+ null, null, null, null, null, null,null);
}
public ExecutionContextImpl(TypeSystemImpl ts, Map<String, Variable> globalVars) {
this(new ResourceManagerDefaultImpl(), null, ts, new HashMap<String, Variable>(), globalVars, null, null, null,
- null, null, null);
+ null, null, null,null);
}
public ExecutionContextImpl(ResourceManager resourceManager, TypeSystemImpl typeSystem,
Map<String, Variable> globalVars) {
this(resourceManager, null, typeSystem, new HashMap<String, Variable>(), globalVars, null, null, null, null,
- null, null);
+ null, null,null);
}
public ExecutionContextImpl(ResourceManager resourceManager, Resource resource, TypeSystemImpl typeSystem,
Map<String, Variable> variables, Map<String, Variable> globalVars, ProgressMonitor monitor,
ExceptionHandler exceptionHandler, List<Around> advices, NullEvaluationHandler neh2,
- Map<Resource, Set<Extension>> extensionPerResourceMap, Callback callback) {
+ Map<Resource, Set<Extension>> extensionPerResourceMap, Callback callback, Cache<Triplet<Resource,String,List<Type>>,Extension> extensionsForNameAndTypesCache) {
if (extensionPerResourceMap != null) {
this.allExtensionsPerResource = extensionPerResourceMap;
}
else {
this.allExtensionsPerResource = new HashMap<Resource, Set<Extension>>();
}
+ if (extensionsForNameAndTypesCache!=null)
+ this.extensionsForNameAndTypesCache = extensionsForNameAndTypesCache;
this.resourceManager = resourceManager;
this.currentResource = resource;
this.typeSystem = typeSystem;
@@ -221,7 +225,7 @@ public class ExecutionContextImpl implements ExecutionContext {
public ExecutionContextImpl cloneContext() {
return new ExecutionContextImpl(resourceManager, currentResource, typeSystem, variables, globalVars, monitor,
- exceptionHandler, registeredExtensionAdvices, nullEvaluationHandler, allExtensionsPerResource, callback);
+ exceptionHandler, registeredExtensionAdvices, nullEvaluationHandler, allExtensionsPerResource, callback, extensionsForNameAndTypesCache);
}
public void setFileEncoding(final String encoding) {
@@ -276,18 +280,24 @@ public class ExecutionContextImpl implements ExecutionContext {
return currentResource;
}
- protected Map<Resource, Set<Extension>> allExtensionsPerResource = null;
public Set<? extends Extension> getAllExtensions() {
- Set<Extension> allExtensions = allExtensionsPerResource.get(currentResource());
+ return internalAllExtensions(currentResource());
+ }
+
+ protected Map<Resource, Set<Extension>> allExtensionsPerResource = null;
+
+ private Set<? extends Extension> internalAllExtensions(Resource currentResource2) {
+ Set<Extension> allExtensions = allExtensionsPerResource.get(currentResource2);
if (allExtensions == null) {
+ ExecutionContext ctx = this.cloneWithResource(currentResource2);
allExtensions = new HashSet<Extension>();
- final Resource res = currentResource();
+ final Resource res = currentResource2;
if (res != null) {
if (res instanceof XtendFile) {
final List<Extension> extensionList = ((XtendFile) res).getExtensions();
for (Extension element : extensionList) {
- element.init(this);
+ element.init(ctx);
allExtensions.add(advise(element));
}
}
@@ -297,7 +307,7 @@ public class ExecutionContextImpl implements ExecutionContext {
final XtendFile extFile = (XtendFile) o;
if (extFile == null)
throw new RuntimeException("Unable to load extension file : " + extension);
- final ExecutionContext ctx = cloneWithResource(extFile);
+ ctx = cloneWithResource(extFile);
final List<Extension> extensionList = extFile.getPublicExtensions(resourceManager, ctx);
for (final Extension element : extensionList) {
element.init(ctx);
@@ -309,9 +319,17 @@ public class ExecutionContextImpl implements ExecutionContext {
}
return allExtensions;
}
+
+ protected Cache<Triplet<Resource,String,List<Type>>, Extension> extensionsForNameAndTypesCache = new Cache<Triplet<Resource,String,List<Type>>, Extension>(){
+
+ @Override
+ protected Extension createNew(Triplet<Resource, String, List<Type>> arg0) {
+ return PolymorphicResolver.getExtension(internalAllExtensions(arg0.getFirst()), arg0.getSecond(), arg0.getThird());
+ }};
public Extension getExtensionForTypes(final String functionName, final Type[] parameterTypes) {
- return PolymorphicResolver.getExtension(getAllExtensions(), functionName, Arrays.asList(parameterTypes));
+ return extensionsForNameAndTypesCache.get(new Triplet<Resource, String, List<Type>>(currentResource(),functionName,Arrays.asList(parameterTypes)));
+// return PolymorphicResolver.getExtension(getAllExtensions(), functionName, Arrays.asList(parameterTypes));
}
public Extension getExtension(final String functionName, final Object[] actualParameters) {
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/Resource.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/Resource.java
index 2509edf..bfa3ab1 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/Resource.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/expression/Resource.java
@@ -19,5 +19,7 @@ public interface Resource {
public String[] getImportedNamespaces();
public String[] getImportedExtensions();
+
+
}