Ignore:
Timestamp:
2021-04-12T00:16:06+02:00 (4 years ago)
Author:
simon04
Message:

see #20745 - Avoid heap allocations due to BBox in IPrimitive.getBBox

Cache and return an immutable bounding box.

37.75% in MapCSSTagCheckerPerformanceTest#testCity amount to BBox::new via IPrimitive.getBBox

File:
1 edited

Legend:

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

    r17357 r17752  
    441441    @Override
    442442    public BBox getBBox() {
    443         if (getDataSet() != null && bbox != null)
    444             return new BBox(bbox); // use cached value
     443        if (getDataSet() != null && bbox != null) {
     444            return this.bbox; // use cached immutable value
     445        }
    445446
    446447        BBox box = new BBox();
    447448        addToBBox(box, new HashSet<PrimitiveId>());
    448         if (getDataSet() != null)
    449             setBBox(box); // set cache
    450         return new BBox(box);
     449        if (getDataSet() == null) {
     450            return box;
     451        }
     452        setBBox(box); // set cached immutable value
     453        return this.bbox;
    451454    }
    452455
    453456    private void setBBox(BBox bbox) {
    454         this.bbox = bbox;
     457        this.bbox = bbox == null ? null : bbox.toImmutable();
    455458    }
    456459
Note: See TracChangeset for help on using the changeset viewer.