I ran FindBugs code analyzer (http://findbugs.sourceforge.net/) on JTS 1.9. It 
revealed several potential problems.

*) fall through switch statement in DefaultCoordinateSequence
  method: "setOrdinate" should have "break" after case

  this class is deprecated so no fix is necessary

*) unused package local variables in EdgeSetIntersector
   List edges0
   List edges1
     are never used

*) 7 inner classes that can be made static
   - it improves speed and lowers memory consumption

*) and others


---- PERFORMANCE
*) replace new Integer(<value>) with Integer.valueOf(<value>)
    - all values from range -128...+127 are cached (no new allocations) - it's 
faster

   PLACES:
    PrecisionModel.compareTo
    MonotoneChainIndexer.getChainStartIndices
    MonotoneChainBuilder.getChainStartIndices
    SegmentNodeList.findCollapsesFromExistingVertices
    SegmentNodeList.findCollapsesFromInsertedNodes

*) replace Math.sqrt(2.0) with constant in OctogonalEnvelope.expandBy
     Math.sqrt(2.0) is expensive to compute and Java hasn't constant methods as 
C++ so the compilers preprocessor can't replace invakestatic Math.sqrt with 
constant value. I think that Math.sqrt is directed to StrictMath.sqrt that 
should correctly deal with NaN and Infinity values according to IEEE 754.


*) I suggest improve HCoordinate.intersection. There is allocated ~24MB for 
HCoordinate in memory (original JTS-1.9). After suggested change only ~8MB is 
allocated. There is no visible impact because all allocations are made fast in 
young generation and immediately discarded without moving to old generation. 
But still it is less work for GC.

public static Coordinate intersection(
      Coordinate p1, Coordinate p2,
      Coordinate q1, Coordinate q2)
      throws NotRepresentableException
  {
    HCoordinate l1 = new HCoordinate(p1, p2);        // removed creation of 
HCoordinate from Coordinate
    HCoordinate l2 = new HCoordinate(q1, q2);        // removed creation of 
HCoordinate from Coordinate
    HCoordinate intHCoord = new HCoordinate(l1, l2);
    Coordinate intPt = intHCoord.getCoordinate();
    return intPt;
  }


//  NEW constructor for HCoordinate that accepts two Coordinate values instead 
of two HCoordinate
//  it is simplified due to HCoordinate.w = 1.0 when created from Coordinate

  public HCoordinate(Coordinate p1, Coordinate p2) {
    x = p1.y - p2.y;
    y = p2.x - p1.x;
    w = p1.x * p2.y - p2.x * p1.y;
  }


_______________________________________________
jts-devel mailing list
[email protected]
http://lists.refractions.net/mailman/listinfo/jts-devel

Reply via email to