Eliminate unnecessary storage of graph objects in map objects. 12/3912/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Tue, 25 Feb 2020 16:32:21 +0000 (18:32 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 26 Feb 2020 12:10:24 +0000 (14:10 +0200)
gitlab #482

Change-Id: Id600bda6892857a376cd169219636dc0300763d4

bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/Mapping.java

index c2ecdf1b1679fe7f9fd5bd21ed9a0cef090ea63d..1589e94326ef2be74755dbd1e114895bdc111ca1 100644 (file)
@@ -79,7 +79,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
                link.type = type;
                link.domainElement = domainElement;
                domain.put(domainElement, link);
-               type.createDomain(g, new RangeToDomain(g), domainElement, link.rangeElement);
+               type.createDomain(g, new RangeToDomain(), domainElement, link.rangeElement);
                
         // TODO Should we do this only if the mapping is listening?
         domainModified(link);
@@ -92,7 +92,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
                link.type = type;
                link.rangeElement = rangeElement;
                range.put(rangeElement, link);
-               type.createRange(g, new DomainToRange(g), link.domainElement, rangeElement);
+               type.createRange(g, new DomainToRange(), link.domainElement, rangeElement);
        }
        
        Set<Domain> domainSet = new AbstractSet<Domain>() {
@@ -173,10 +173,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        class DomainToRange implements IForwardMapping<Domain, Range> {
 
-               ReadGraph g;
-               
-               public DomainToRange(ReadGraph g) {
-                       this.g = g;
+               public DomainToRange() {
                }
 
                @Override
@@ -197,10 +194,10 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
                    link.domainModified = true;
                    modifiedDomainLinks.add(link);
                            domain.put(element, link);           
-                           createRange(g, link);       
+                           createRange(graph, link);   
                        }
                        else if(link.type == null) 
-                               createRange(g, link);
+                               createRange(graph, link);
             return link.rangeElement;
                }
                
@@ -213,12 +210,10 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        
        class RangeToDomain extends DomainToRange implements IBackwardMapping<Domain, Range> {
 
-               WriteGraph g;
-               
-               public RangeToDomain(WriteGraph g) {
-                       super(g);
-                       this.g = g;
+               public RangeToDomain() {
+                       super();
                }
+               
                @Override
                public Domain inverseGet(Range element) {
                        
@@ -237,10 +232,10 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
                            link.rangeModified = true;
                 modifiedRangeLinks.add(link);
                            range.put(element, link);
-                           createDomain(g, link);                              
+                           createDomain(graph, link);                          
                        }
                        else if(link.type == null)
-                               createDomain(g, link);
+                               createDomain(graph, link);
                        return link.domainElement;
                }
                
@@ -265,7 +260,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        @Override
        public synchronized Collection<Domain> updateDomain(WriteGraph g) throws MappingException {
            LOGGER.trace("Mapping.updateDomain");
-               RangeToDomain map = new RangeToDomain(g);
+               RangeToDomain map = new RangeToDomain();
                ArrayList<Domain> updated = new ArrayList<Domain>();
                while(!modifiedRangeLinks.isEmpty()) {
                    LOGGER.trace("    modifiedRangeLinks.size() = " + modifiedRangeLinks.size());
@@ -293,7 +288,7 @@ public class Mapping<Domain, Range> implements IMapping<Domain, Range> {
        @Override
        public synchronized Collection<Range> updateRange(ReadGraph g) throws MappingException {
            LOGGER.trace("Mapping.updateRange");
-               DomainToRange map = new DomainToRange(g);
+               DomainToRange map = new DomainToRange();
                ArrayList<Range> updated = new ArrayList<Range>();
                while(!modifiedDomainLinks.isEmpty()) {             
                    LOGGER.trace("    modifiedDomainLinks.size() = " + modifiedDomainLinks.size());