eac15b7
From 0dcc4f04883cfd87a3cbf814f61c603c7d066399 Mon Sep 17 00:00:00 2001
eac15b7
From: Michael Simacek <msimacek@redhat.com>
eac15b7
Date: Wed, 2 May 2018 15:22:08 +0200
eac15b7
Subject: [PATCH] Avoid presizing arrays
eac15b7
eac15b7
---
eac15b7
 .../common/util/concurrent/AtomicDoubleArray.java    | 12 +++++++-----
eac15b7
 1 file changed, 7 insertions(+), 5 deletions(-)
eac15b7
eac15b7
diff --git a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
eac15b7
index 407cd7c..14d0e48 100644
eac15b7
--- a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
eac15b7
+++ b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
eac15b7
@@ -16,8 +16,12 @@ package com.google.common.util.concurrent;
eac15b7
 import static java.lang.Double.doubleToRawLongBits;
eac15b7
 import static java.lang.Double.longBitsToDouble;
eac15b7
 
eac15b7
+import java.util.ArrayList;
eac15b7
+import java.util.List;
eac15b7
 import java.util.concurrent.atomic.AtomicLongArray;
eac15b7
 
eac15b7
+import com.google.common.primitives.Longs;
eac15b7
+
eac15b7
 /**
eac15b7
  * A {@code double} array in which elements may be updated atomically.
eac15b7
  * See the {@link java.util.concurrent.atomic} package specification
eac15b7
@@ -256,13 +260,11 @@ public class AtomicDoubleArray implements java.io.Serializable {
eac15b7
       throws java.io.IOException, ClassNotFoundException {
eac15b7
     s.defaultReadObject();
eac15b7
 
eac15b7
-    // Read in array length and allocate array
eac15b7
     int length = s.readInt();
eac15b7
-    this.longs = new AtomicLongArray(length);
eac15b7
-
eac15b7
-    // Read in all elements in the proper order.
eac15b7
+    List<Long> builder = new ArrayList<Long>();
eac15b7
     for (int i = 0; i < length; i++) {
eac15b7
-      set(i, s.readDouble());
eac15b7
+      builder.add(doubleToRawLongBits(s.readDouble()));
eac15b7
     }
eac15b7
+    this.longs = new AtomicLongArray(Longs.toArray(builder));
eac15b7
   }
eac15b7
 }
eac15b7
-- 
eac15b7
2.17.0
eac15b7