Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions library/src/com/google/common/geometry/S2BooleanOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -1045,15 +1045,21 @@ public void addCrossingGraphEdge(
}

/** Clears all the contents and reinitializes to contain 'size' empty CrossingGraphVectors. */
public void reinitialize(int size) {
this.size = size;
public void reinitialize(int newSize) {
// Clear any vectors that are no longer in use, to release their memory.
for (int v = newSize; v < this.size; v++) {
if (vectors[v] != null) {
vectors[v].clear();
}
}
this.size = newSize;

// Only reallocate a larger array if required.
if (vectors.length < size) {
vectors = Arrays.copyOf(vectors, size);
if (vectors.length < newSize) {
vectors = Arrays.copyOf(vectors, newSize);
}
// Clear the contents of each vector.
for (int v = 0; v < size; ++v) {
for (int v = 0; v < newSize; ++v) {
if (vectors[v] == null) {
vectors[v] = new CrossingGraphEdgeVector();
} else {
Expand Down