Skip to content

Commit

Permalink
Switch to try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexklibisz committed Mar 23, 2024
1 parent 3842f08 commit 1d509dc
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -21,18 +21,19 @@ public FloatArrayBuffer() {
}

public void append(float f) {
// TODO: Test whether try/catch is faster than if.
// try {
// this.array[index++] = f;
// } catch (IndexOutOfBoundsException ex) {
// this.array = Arrays.copyOf(this.array, this.array.length * 2);
// this.array[index - 1] = f;
// }
// if statement gets about 557013.799 ops/s on r6i.4xlarge.
if (index == this.array.length) {
// System.out.printf("Growing from %d to %d\n", this.array.length, this.array.length * 2);
this.array = Arrays.copyOf(this.array, this.array.length * 2);
}
this.array[index++] = f;
// try/catch gets ...
try {
this.array[index++] = f;
} catch (IndexOutOfBoundsException ex) {
this.array = Arrays.copyOf(this.array, this.array.length * 2);
this.array[index - 1] = f;
}
}

public float[] toArray() {

0 comments on commit 1d509dc

Please sign in to comment.