Skip to content

Commit

Permalink
[FLINK-6589] [core] Deserialize ArrayList with capacity of size+1 to …
Browse files Browse the repository at this point in the history
…prevent growth.

This closes apache#3912.
  • Loading branch information
fhueske committed May 17, 2017
1 parent d85d969 commit 2bfead7
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean isImmutableType() {
@Override
public TypeSerializer<List<T>> duplicate() {
TypeSerializer<T> duplicateElement = elementSerializer.duplicate();
return duplicateElement == elementSerializer ? this : new ListSerializer<T>(duplicateElement);
return duplicateElement == elementSerializer ? this : new ListSerializer<>(duplicateElement);
}

@Override
Expand Down Expand Up @@ -129,7 +129,8 @@ public void serialize(List<T> list, DataOutputView target) throws IOException {
@Override
public List<T> deserialize(DataInputView source) throws IOException {
final int size = source.readInt();
final List<T> list = new ArrayList<>(size);
// create new list with (size + 1) capacity to prevent expensive growth when a single element is added
final List<T> list = new ArrayList<>(size + 1);
for (int i = 0; i < size; i++) {
list.add(elementSerializer.deserialize(source));
}
Expand Down

0 comments on commit 2bfead7

Please sign in to comment.