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