Changeset 15934 in josm


Ignore:
Timestamp:
2020-02-26T01:52:17+01:00 (4 years ago)
Author:
simon04
Message:

see #18749 - Intern strings to reduce memory footprint

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r15902 r15934  
    397397            min_zoom = i.defaultMinZoom;
    398398            cookies = i.cookies;
    399             icon = i.icon == null ? null : i.icon.intern();
     399            icon = intern(i.icon);
    400400            description = i.description;
    401401            category = i.category != null ? i.category.getCategoryString() : null;
     
    555555        if (e.projections != null && !e.projections.isEmpty()) {
    556556            // split generates null element on empty string which gives one element Array[null]
    557             serverProjections = Arrays.asList(e.projections.split(","));
    558         }
    559         attributionText = e.attribution_text;
     557            setServerProjections(Arrays.asList(e.projections.split(",")));
     558        }
     559        attributionText = intern(e.attribution_text);
    560560        attributionLinkURL = e.attribution_url;
    561561        permissionReferenceURL = e.permission_reference_url;
     
    567567        termsOfUseText = e.terms_of_use_text;
    568568        termsOfUseURL = e.terms_of_use_url;
    569         countryCode = e.country_code;
    570         icon = e.icon == null ? null : e.icon.intern();
     569        countryCode = intern(e.country_code);
     570        icon = intern(e.icon);
    571571        if (e.noTileHeaders != null) {
    572572            noTileHeaders = e.noTileHeaders.toMap();
     
    633633        this.overlay = i.overlay;
    634634        // do not copy field {@code mirrors}
    635         this.icon = i.icon == null ? null : i.icon.intern();
     635        this.icon = intern(i.icon);
    636636        this.isGeoreferenceValid = i.isGeoreferenceValid;
    637637        this.defaultLayers = i.defaultLayers;
     
    639639        this.transparent = i.transparent;
    640640        this.minimumTileExpire = i.minimumTileExpire;
    641         this.categoryOriginalString = i.categoryOriginalString;
     641        this.categoryOriginalString = intern(i.categoryOriginalString);
    642642        this.category = i.category;
    643643    }
     
    868868     */
    869869    public void setAttributionText(String text) {
    870         attributionText = text;
     870        attributionText = intern(text);
    871871    }
    872872
     
    955955
    956956        if (serverProjections.isEmpty()) {
    957             serverProjections = new ArrayList<>();
    958957            Matcher m = Pattern.compile(".*\\{PROJ\\(([^)}]+)\\)\\}.*").matcher(url.toUpperCase(Locale.ENGLISH));
    959958            if (m.matches()) {
    960                 for (String p : m.group(1).split(",")) {
    961                     serverProjections.add(p);
    962                 }
     959                setServerProjections(Arrays.asList(m.group(1).split(",")));
    963960            }
    964961        }
     
    10641061        if (LanguageInfo.isBetterLanguage(langDescription, language)) {
    10651062            this.description = isdefault ? tr(description) : description;
    1066             this.langDescription = language;
     1063            this.langDescription = intern(language);
    10671064        }
    10681065    }
     
    11551152     */
    11561153    public void setCountryCode(String countryCode) {
    1157         this.countryCode = countryCode;
     1154        this.countryCode = intern(countryCode);
    11581155    }
    11591156
     
    11901187     */
    11911188    public void setIcon(String icon) {
    1192         this.icon = icon == null ? null : icon.intern();
     1189        this.icon = intern(icon);
    11931190    }
    11941191
     
    12091206    public void setServerProjections(Collection<String> serverProjections) {
    12101207        CheckParameterUtil.ensureParameterNotNull(serverProjections, "serverProjections");
    1211         this.serverProjections = new ArrayList<>(serverProjections);
     1208        this.serverProjections = serverProjections.stream()
     1209                .map(String::intern)
     1210                .collect(Collectors.collectingAndThen(Collectors.toList(), Utils::toUnmodifiableList));
    12121211    }
    12131212
     
    13551354     */
    13561355    public void setImageryCategoryOriginalString(String categoryOriginalString) {
    1357         this.categoryOriginalString = categoryOriginalString;
     1356        this.categoryOriginalString = intern(categoryOriginalString);
    13581357    }
    13591358
     
    16451644        }
    16461645    }
     1646
     1647    private static String intern(String string) {
     1648        return string == null ? null : string.intern();
     1649    }
    16471650}
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r13766 r15934  
    8484    public RelationMember(String role, OsmPrimitive member) {
    8585        CheckParameterUtil.ensureParameterNotNull(member, "member");
    86         this.role = Optional.ofNullable(role).orElse("");
     86        this.role = Optional.ofNullable(role).orElse("").intern();
    8787        this.member = member;
    8888    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r15671 r15934  
    259259         */
    260260        public SimpleKeyValueCondition(String k, String v) {
    261             this.k = k;
    262             this.v = v;
     261            this.k = k.intern();
     262            this.v = v.intern();
    263263        }
    264264
     
    311311         */
    312312        public KeyValueCondition(String k, String v, Op op, boolean considerValAsKey) {
    313             this.k = k;
    314             this.v = v;
     313            this.k = k.intern();
     314            this.v = v.intern();
    315315            this.op = op;
    316316            this.considerValAsKey = considerValAsKey;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/LiteralExpression.java

    r14484 r15934  
    2020    public LiteralExpression(Object literal) {
    2121        CheckParameterUtil.ensureParameterNotNull(literal);
    22         this.literal = literal;
     22        this.literal = literal instanceof String ? ((String) literal).intern() : literal;
    2323    }
    2424
Note: See TracChangeset for help on using the changeset viewer.