orion / rpms / guava

Forked from rpms/guava 2 years ago
Clone
Blob Blame History Raw
From 0dcc4f04883cfd87a3cbf814f61c603c7d066399 Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Wed, 2 May 2018 15:22:08 +0200
Subject: [PATCH] Avoid presizing arrays

---
 .../common/util/concurrent/AtomicDoubleArray.java    | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
index 407cd7c..14d0e48 100644
--- a/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
+++ b/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java
@@ -16,8 +16,12 @@ package com.google.common.util.concurrent;
 import static java.lang.Double.doubleToRawLongBits;
 import static java.lang.Double.longBitsToDouble;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicLongArray;
 
+import com.google.common.primitives.Longs;
+
 /**
  * A {@code double} array in which elements may be updated atomically.
  * See the {@link java.util.concurrent.atomic} package specification
@@ -256,13 +260,11 @@ public class AtomicDoubleArray implements java.io.Serializable {
       throws java.io.IOException, ClassNotFoundException {
     s.defaultReadObject();
 
-    // Read in array length and allocate array
     int length = s.readInt();
-    this.longs = new AtomicLongArray(length);
-
-    // Read in all elements in the proper order.
+    List<Long> builder = new ArrayList<Long>();
     for (int i = 0; i < length; i++) {
-      set(i, s.readDouble());
+      builder.add(doubleToRawLongBits(s.readDouble()));
     }
+    this.longs = new AtomicLongArray(Longs.toArray(builder));
   }
 }
-- 
2.17.0