Changeset 8566 in josm for trunk


Ignore:
Timestamp:
2015-07-04T18:35:10+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #11653 - AbstractPrimitive.getKeys optimization (patch by shinigami)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r8565 r8566  
    469469    /**
    470470     * The key/value list for this primitive.
    471      *
    472471     */
    473472    protected String[] keys;
     
    481480    @Override
    482481    public Map<String, String> getKeys() {
    483         Map<String, String> result = new HashMap<>();
    484         String[] keys = this.keys;
    485         if (keys != null) {
    486             for (int i = 0; i < keys.length; i += 2) {
    487                 result.put(keys[i], keys[i + 1]);
    488             }
    489         }
     482        final String[] keys = this.keys;
     483        if (keys == null || keys.length == 0) {
     484            return Collections.emptyMap();
     485        } else if (keys.length == 2) {
     486            return Collections.singletonMap(keys[0], keys[1]);
     487        }
     488
     489        final Map<String, String> result = new HashMap<>();
     490        for (int i = 0; i < keys.length; i += 2) {
     491            result.put(keys[i], keys[i + 1]);
     492        }
     493
    490494        return result;
    491495    }
Note: See TracChangeset for help on using the changeset viewer.