From 053a1c506918cd662c9b18e7412dd29cddaa4b1e Mon Sep 17 00:00:00 2001 From: Moritz Eysholdt Date: Tue, 11 Oct 2016 16:17:48 +0200 Subject: [PATCH] revert ef25bcbe4c1bb461a27dfab50654be2b8d497803, no performance increase --- .../analysis/ContextPDAProvider.java | 7 +-- .../analysis/ContextTypePDAProvider.java | 6 +-- .../analysis/GrammarPDAProvider.java | 1 - .../serializer/analysis/SerializerPDA.java | 44 ++++--------------- 4 files changed, 12 insertions(+), 46 deletions(-) diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextPDAProvider.java b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextPDAProvider.java index 5968dbb47..2a83a353a 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextPDAProvider.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextPDAProvider.java @@ -208,12 +208,10 @@ public class ContextPDAProvider implements IContextPDAProvider { } else { try { SerializerPDA rulePda = extract(pda.getStop()); - rulePda.setGrammar(grammar); result.put(contexts, rulePda); for (ISerState state : actions) { Action action = (Action) state.getGrammarElement(); SerializerPDA actionPda = extract(state); - actionPda.setGrammar(grammar); actionPdas.put(action, actionPda); actionContexts.putAll(action, contexts); } @@ -223,7 +221,7 @@ public class ContextPDAProvider implements IContextPDAProvider { } } for (Map.Entry> action : actionPdas.asMap().entrySet()) { - SerializerPDA merged = merge(grammar, new ActionContext(null, action.getKey()), action.getValue()); + SerializerPDA merged = merge(new ActionContext(null, action.getKey()), action.getValue()); Set> parameterPermutations = Sets.newLinkedHashSet(); for (ISerializationContext container : actionContexts.get(action.getKey())) { parameterPermutations.add(container.getEnabledBooleanParameters()); @@ -240,13 +238,12 @@ public class ContextPDAProvider implements IContextPDAProvider { return result.create(); } - protected SerializerPDA merge(Grammar grammar, ISerializationContext context, Collection pdas) { + protected SerializerPDA merge(ISerializationContext context, Collection pdas) { if (pdas.isEmpty()) throw new IllegalStateException(); if (pdas.size() == 1) return pdas.iterator().next(); SerializerPDA merged = factory.create(null, null); - merged.setGrammar(grammar); Map oldToNew = Maps.newHashMap(); for (Pda pda : pdas) { oldToNew.put(pda.getStop(), merged.getStop()); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextTypePDAProvider.java b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextTypePDAProvider.java index 7edd19021..a3da1dcbf 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextTypePDAProvider.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/ContextTypePDAProvider.java @@ -242,11 +242,9 @@ public class ContextTypePDAProvider implements IContextTypePDAProvider { return collector.getTypes(); } - protected Pda filterByType(Grammar grammar, Pda contextPda, EClass type, - Map distances) { + protected Pda filterByType(Pda contextPda, EClass type, Map distances) { TypeFilter typeFilter = newTypeFilter(type); SerializerPDA pda = pdaUtil.filterEdges(contextPda, typeFilter, distances, factory); - pda.setGrammar(grammar); return pda; } @@ -271,7 +269,7 @@ public class ContextTypePDAProvider implements IContextTypePDAProvider { } } else { for (EClass type : types) { - Pda filtered = filterByType(grammar, contextPDA, type, distances); + Pda filtered = filterByType(contextPDA, type, distances); for (ISerializationContext parent : parents) { TypeContext typeContext = new TypeContext(parent, type); builder.put(typeContext, filtered); diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/GrammarPDAProvider.java b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/GrammarPDAProvider.java index 5ec7d52ff..6edb4cc8e 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/GrammarPDAProvider.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/GrammarPDAProvider.java @@ -168,7 +168,6 @@ public class GrammarPDAProvider implements IGrammarPDAProvider { SerializerParserRuleCfg cfg = new SerializerParserRuleCfg(flattened, entryRule); SerializerParserRuleFollowerFunction ff = new SerializerParserRuleFollowerFunction(cfg); SerializerPDA pda = pdaUtil.create(cfg, ff, new ToOriginal(factory)); - pda.setGrammar(flattened); // SerializerPDA pda = pdaUtil.create(cfg, ff, factory); return pda; } diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/SerializerPDA.java b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/SerializerPDA.java index 87a6a97c6..ccb9c2554 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/SerializerPDA.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/serializer/analysis/SerializerPDA.java @@ -10,7 +10,6 @@ package org.eclipse.xtext.serializer.analysis; import java.util.List; import org.eclipse.xtext.AbstractElement; -import org.eclipse.xtext.Grammar; import org.eclipse.xtext.GrammarUtil; import org.eclipse.xtext.RuleCall; import org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch; @@ -148,7 +147,7 @@ public class SerializerPDA implements Pda { @Override public int hashCode() { - return (grammarElement != null ? grammarElement.hashCode() : 1) + type.ordinal(); + return (grammarElement != null ? grammarElement.hashCode() : 1) * type.hashCode(); } @Override @@ -183,8 +182,6 @@ public class SerializerPDA implements Pda { protected SerializerPDA.SerializerPDAState start; protected SerializerPDA.SerializerPDAState stop; - private String identity = null; - private Grammar grammar = null; public SerializerPDA(SerializerPDA.SerializerPDAState start, SerializerPDA.SerializerPDAState stop) { super(); @@ -196,8 +193,7 @@ public class SerializerPDA implements Pda { public boolean equals(Object obj) { if (obj == null || obj.getClass() != getClass()) return false; - SerializerPDA other = (SerializerPDA) obj; - return getIdentity().equals(other.getIdentity()); + return new NfaUtil().equalsIgnoreOrder(this, (SerializerPDA) obj); } @Override @@ -226,39 +222,15 @@ public class SerializerPDA implements Pda { public SerializerPDAState getStop() { return stop; } - - public Grammar getGrammar() { - return grammar; - } - - public void setGrammar(Grammar grammar) { - this.grammar = grammar; - } - - protected String getIdentity() { - if (identity != null) { - return identity; - } - if (grammar == null) { - throw new IllegalStateException(); - } - final GrammarElementDeclarationOrder order = GrammarElementDeclarationOrder.get(grammar); - identity = new NfaUtil().identityString(this, new Function() { - @Override - public String apply(ISerState input) { - AbstractElement grammarElement = input.getGrammarElement(); - if (grammarElement != null) { - return order.getElementID(grammarElement) + "_" + input.getType().name(); - } - return input.getType().name(); - } - }); - return identity; - } @Override public int hashCode() { - return getIdentity().hashCode(); + int r = 0; + if (start != null && start.followers != null) + for (ISerState s : start.followers) + if (s != null) + r += s.hashCode(); + return r; } @Override