1a98ae8
From c6497b79ee766206ba27c6b33391e1d5e572e662 Mon Sep 17 00:00:00 2001
1a98ae8
From: Michael Simacek <msimacek@redhat.com>
1a98ae8
Date: Wed, 2 May 2018 15:22:08 +0200
1a98ae8
Subject: [PATCH] Avoid presizing arrays
1a98ae8
1a98ae8
Backported version of:
1a98ae8
https://github.com/google/guava/commit/f89ece5721b2f637fe754937ff1f3c86d80bb196
1a98ae8
1a98ae8
Ignoring GWT, as we don't ship it. Using ArrayList, because
1a98ae8
ImmutableLongArray is not available.
1a98ae8
---
1a98ae8
 .../common/util/concurrent/AtomicDoubleArray.java     | 11 ++++++-----
1a98ae8
 1 file changed, 6 insertions(+), 5 deletions(-)
1a98ae8
1a98ae8
diff --git a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
1a98ae8
index e939672..23a2535 100644
1a98ae8
--- a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
1a98ae8
+++ b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
1a98ae8
@@ -17,7 +17,10 @@ import static java.lang.Double.doubleToRawLongBits;
1a98ae8
 import static java.lang.Double.longBitsToDouble;
1a98ae8
 
1a98ae8
 import com.google.common.annotations.GwtIncompatible;
1a98ae8
+import com.google.common.primitives.Longs;
1a98ae8
 import com.google.errorprone.annotations.CanIgnoreReturnValue;
1a98ae8
+import java.util.ArrayList;
1a98ae8
+import java.util.List;
1a98ae8
 import java.util.concurrent.atomic.AtomicLongArray;
1a98ae8
 
1a98ae8
 /**
1a98ae8
@@ -261,13 +264,11 @@ public class AtomicDoubleArray implements java.io.Serializable {
1a98ae8
       throws java.io.IOException, ClassNotFoundException {
1a98ae8
     s.defaultReadObject();
1a98ae8
 
1a98ae8
-    // Read in array length and allocate array
1a98ae8
     int length = s.readInt();
1a98ae8
-    this.longs = new AtomicLongArray(length);
1a98ae8
-
1a98ae8
-    // Read in all elements in the proper order.
1a98ae8
+    List<Long> builder = new ArrayList<Long>();
1a98ae8
     for (int i = 0; i < length; i++) {
1a98ae8
-      set(i, s.readDouble());
1a98ae8
+      builder.add(doubleToRawLongBits(s.readDouble()));
1a98ae8
     }
1a98ae8
+    this.longs = new AtomicLongArray(Longs.toArray(builder));
1a98ae8
   }
1a98ae8
 }
1a98ae8
-- 
1a98ae8
2.17.0
1a98ae8