flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [2/7] flink git commit: [FLINK-6005] [misc] Fix some ArrayList initializations without initial size
Date Fri, 10 Mar 2017 13:42:44 GMT
[FLINK-6005] [misc] Fix some ArrayList initializations without initial size

This closes #3499


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

Branch: refs/heads/master
Commit: bb1197d9162a630c87d47defc5d0c42de6726feb
Parents: a87b527
Author: Nico Kruber <nico@data-artisans.com>
Authored: Thu Mar 9 12:24:33 2017 +0100
Committer: Stephan Ewen <sewen@apache.org>
Committed: Fri Mar 10 10:58:07 2017 +0100

----------------------------------------------------------------------
 .../api/common/typeutils/base/ListSerializerTest.java     |  5 +++--
 .../apache/flink/graph/library/SummarizationITCase.java   |  5 +++--
 .../java/org/apache/flink/graph/generator/TestUtils.java  | 10 ++++++----
 .../io/network/serialization/LargeRecordsTest.java        |  8 ++++----
 4 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/bb1197d9/flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/ListSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/ListSerializerTest.java
b/flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/ListSerializerTest.java
index 28cdc13..2de6bec 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/ListSerializerTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/ListSerializerTest.java
@@ -71,8 +71,9 @@ public class ListSerializerTest extends SerializerTestBase<List<Long>>
{
 			list7.add(rnd.nextLong());
 		}
 
-		final List<Long> list8 = new ArrayList<>();
-		for (int i = 0; i < rnd.nextInt(200); i++) {
+		int list8Len = rnd.nextInt(200);
+		final List<Long> list8 = new ArrayList<>(list8Len);
+		for (int i = 0; i < list8Len; i++) {
 			list8.add(rnd.nextLong());
 		}
 

http://git-wip-us.apache.org/repos/asf/flink/blob/bb1197d9/flink-libraries/flink-gelly-examples/src/test/java/org/apache/flink/graph/library/SummarizationITCase.java
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-gelly-examples/src/test/java/org/apache/flink/graph/library/SummarizationITCase.java
b/flink-libraries/flink-gelly-examples/src/test/java/org/apache/flink/graph/library/SummarizationITCase.java
index 43514dc..fe4cd24 100644
--- a/flink-libraries/flink-gelly-examples/src/test/java/org/apache/flink/graph/library/SummarizationITCase.java
+++ b/flink-libraries/flink-gelly-examples/src/test/java/org/apache/flink/graph/library/SummarizationITCase.java
@@ -185,8 +185,9 @@ public class SummarizationITCase extends MultipleProgramsTestBase {
 	}
 
 	private List<Long> getListFromIdRange(String idRange) {
-		List<Long> result = new ArrayList<>();
-		for (String id : ID_SEPARATOR.split(idRange)) {
+		String[] split = ID_SEPARATOR.split(idRange);
+		List<Long> result = new ArrayList<>(split.length);
+		for (String id : split) {
 			result.add(Long.parseLong(id));
 		}
 		return result;

http://git-wip-us.apache.org/repos/asf/flink/blob/bb1197d9/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/generator/TestUtils.java
----------------------------------------------------------------------
diff --git a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/generator/TestUtils.java
b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/generator/TestUtils.java
index 2cf9eac..23ad31c 100644
--- a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/generator/TestUtils.java
+++ b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/generator/TestUtils.java
@@ -57,9 +57,10 @@ public final class TestUtils {
 	private static <K, VV, EV> void compareVertices(Graph<K, VV, EV> graph, String
expectedVertices)
 			throws Exception {
 		if (expectedVertices != null) {
-			List<String> resultVertices = new ArrayList<>();
+			List<Vertex<K, VV>> vertices = graph.getVertices().collect();
+			List<String> resultVertices = new ArrayList<>(vertices.size());
 
-			for (Vertex<K, VV> vertex : graph.getVertices().collect()) {
+			for (Vertex<K, VV> vertex : vertices) {
 				resultVertices.add(vertex.f0.toString());
 			}
 
@@ -70,9 +71,10 @@ public final class TestUtils {
 	private static <K, VV, EV> void compareEdges(Graph<K, VV, EV> graph, String
expectedEdges)
 			throws Exception {
 		if (expectedEdges != null) {
-			List<String> resultEdges = new ArrayList<>();
+			List<Edge<K, EV>> edges = graph.getEdges().collect();
+			List<String> resultEdges = new ArrayList<>(edges.size());
 
-			for (Edge<K, EV> edge : graph.getEdges().collect()) {
+			for (Edge<K, EV> edge : edges) {
 				resultEdges.add(edge.f0.toString() + "," + edge.f1.toString());
 			}
 

http://git-wip-us.apache.org/repos/asf/flink/blob/bb1197d9/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/serialization/LargeRecordsTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/serialization/LargeRecordsTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/serialization/LargeRecordsTest.java
index 1574fe9..25523db 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/serialization/LargeRecordsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/serialization/LargeRecordsTest.java
@@ -54,8 +54,8 @@ public class LargeRecordsTest {
 
 			final Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(SEGMENT_SIZE),
mock(BufferRecycler.class));
 
-			List<SerializationTestType> originalRecords = new ArrayList<SerializationTestType>();
-			List<SerializationTestType> deserializedRecords = new ArrayList<SerializationTestType>();
+			List<SerializationTestType> originalRecords = new ArrayList<SerializationTestType>((NUM_RECORDS
+ 1) / 2);
+			List<SerializationTestType> deserializedRecords = new ArrayList<SerializationTestType>((NUM_RECORDS
+ 1) / 2);
 			
 			LargeObjectType genLarge = new LargeObjectType();
 			
@@ -154,8 +154,8 @@ public class LargeRecordsTest {
 
 			final Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(SEGMENT_SIZE),
mock(BufferRecycler.class));
 
-			List<SerializationTestType> originalRecords = new ArrayList<SerializationTestType>();
-			List<SerializationTestType> deserializedRecords = new ArrayList<SerializationTestType>();
+			List<SerializationTestType> originalRecords = new ArrayList<>((NUM_RECORDS
+ 1) / 2);
+			List<SerializationTestType> deserializedRecords = new ArrayList<>((NUM_RECORDS
+ 1) / 2);
 			
 			LargeObjectType genLarge = new LargeObjectType();
 			


Mime
View raw message