Changeset 18956 in josm for trunk/src


Ignore:
Timestamp:
2024-01-24T14:11:38+01:00 (10 months ago)
Author:
GerdP
Message:

fix #20405: History browser for complex relations requires lots of memory

  • avoid to create equal instances of RelationMemberData. This is simple and very effective when relations have many versions as most members are the same in each version
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/AbstractParser.java

    r17838 r18956  
    55
    66import java.time.Instant;
     7import java.util.HashMap;
     8import java.util.Map;
    79
    810import org.openstreetmap.josm.data.coor.LatLon;
     
    3133    /** if true, replace user information in input by anonymous user */
    3234    protected boolean useAnonymousUser;
     35    private Map<RelationMemberData, RelationMemberData> memberCache = new HashMap<>();
    3336
    3437    @Override
     
    182185        String role = getMandatoryAttributeString(atts, "role");
    183186        RelationMemberData member = new RelationMemberData(role, type, ref);
    184         ((HistoryRelation) currentPrimitive).addMember(member);
     187        // see #20405: cache equal instances of members
     188        RelationMemberData cachedMember = memberCache .putIfAbsent(member, member);
     189        if (cachedMember == null)
     190            cachedMember = member;
     191        ((HistoryRelation) currentPrimitive).addMember(cachedMember);
    185192    }
    186193
Note: See TracChangeset for help on using the changeset viewer.