Changeset 18470 in josm for trunk


Ignore:
Timestamp:
2022-06-07T17:54:52+02:00 (2 years ago)
Author:
taylor.smock
Message:

Reduce memory allocations and CPU calls in Way#getNodePairs

This reduces memory allocations and CPU calls by ~33% for the method call
by setting the size of the list at construction time.

See #20716 comment:68.

File:
1 edited

Legend:

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

    r18208 r18470  
    157157     */
    158158    public List<Pair<Node, Node>> getNodePairs(boolean sort) {
    159         List<Pair<Node, Node>> chunkSet = new ArrayList<>();
     159        // For a way of size n, there are n - 1 pairs (a -> b, b -> c, c -> d, etc., 4 nodes -> 3 pairs)
     160        List<Pair<Node, Node>> chunkSet = new ArrayList<>(this.getNodesCount() - 1);
    160161        if (isIncomplete()) return chunkSet;
    161162        Node lastN = null;
Note: See TracChangeset for help on using the changeset viewer.