Skip to content

Commit

Permalink
Merge pull request #16 from TimVossen-IF/default-strategy-instance
Browse files Browse the repository at this point in the history
Reuse the same strategy instance
  • Loading branch information
dweiss authored Feb 19, 2021
2 parents d2830d2 + f9477d5 commit 35d82dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* </pre>
*/
public final class BoundedProportionalArraySizingStrategy implements ArraySizingStrategy {

/** Instance of {@link BoundedProportionalArraySizingStrategy} with default values. */
public static final BoundedProportionalArraySizingStrategy DEFAULT_INSTANCE =
new BoundedProportionalArraySizingStrategy();

/**
* Maximum allocable array length (approximately the largest positive integer decreased by the
* array's object header).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public class KTypeArrayDeque<KType>
Preallocable,
Cloneable,
Accountable {

/**
* Reuse the same strategy instance.
*/
private static final BoundedProportionalArraySizingStrategy DEFAULT_SIZING_STRATEGY =
BoundedProportionalArraySizingStrategy.DEFAULT_INSTANCE;

/**
* Internal array for storing elements of the deque.
*/
Expand Down Expand Up @@ -62,7 +69,7 @@ public KTypeArrayDeque() {
* expansion (inclusive).
*/
public KTypeArrayDeque(int expectedElements) {
this(expectedElements, new BoundedProportionalArraySizingStrategy());
this(expectedElements, DEFAULT_SIZING_STRATEGY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public class KTypeArrayList<KType>
new Object [0];
/*! #end !*/;

/**
* Reuse the same strategy instance.
*/
private static final BoundedProportionalArraySizingStrategy DEFAULT_SIZING_STRATEGY =
BoundedProportionalArraySizingStrategy.DEFAULT_INSTANCE;

/**
* Internal array for storing the list. The array may be larger than the current size
* ({@link #size()}).
Expand Down Expand Up @@ -73,7 +79,7 @@ public KTypeArrayList() {
* expansion (inclusive).
*/
public KTypeArrayList(int expectedElements) {
this(expectedElements, new BoundedProportionalArraySizingStrategy());
this(expectedElements, DEFAULT_SIZING_STRATEGY);
}


Expand Down

0 comments on commit 35d82dd

Please sign in to comment.