flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhue...@apache.org
Subject [1/3] flink git commit: [FLINK-6589] [core] Deserialize ArrayList with capacity of size+1 to prevent growth.
Date Wed, 17 May 2017 13:24:39 GMT
Repository: flink
Updated Branches:
  refs/heads/master b6afc06ab -> 2bfead7d9


[FLINK-6589] [core] Deserialize ArrayList with capacity of size+1 to prevent growth.

This closes #3912.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/2bfead7d
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/2bfead7d
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/2bfead7d

Branch: refs/heads/master
Commit: 2bfead7d9bef51713ed203fa7979f71f23525733
Parents: d85d969
Author: Fabian Hueske <fhueske@apache.org>
Authored: Mon May 15 21:41:51 2017 +0200
Committer: Fabian Hueske <fhueske@apache.org>
Committed: Wed May 17 15:24:23 2017 +0200

----------------------------------------------------------------------
 .../apache/flink/api/common/typeutils/base/ListSerializer.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/2bfead7d/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/ListSerializer.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/ListSerializer.java
b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/ListSerializer.java
index aa9808e..1f271fe 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/ListSerializer.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/ListSerializer.java
@@ -82,7 +82,7 @@ public final class ListSerializer<T> extends TypeSerializer<List<T>>
{
 	@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
@@ -129,7 +129,8 @@ public final class ListSerializer<T> extends TypeSerializer<List<T>>
{
 	@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));
 		}


Mime
View raw message