On 07/08/2014 03:56 PM, Martin Buchholz wrote:
On Tue, Jul 8, 2014 at 5:30 AM, Peter Levart <peter.lev...@gmail.com> wrote:

On 07/08/2014 02:20 PM, Peter Levart wrote:

That's right. Not in put(). But in putAll() it can overflow, since the
argument Map can be of any size that fits in int...

I took another look at putAll.  I think we can do more simply, relying on
the checks in capacity and resize:

           int n = m.size();
          if (n == 0)
              return;
-        if (n > threshold) // conservatively pre-expand
-            resize(capacity(n));
+        if (n > size)
+            resize(capacity(n)); // conservatively pre-expand

          for (Entry<? extends K, ? extends V> e : m.entrySet())
              put(e.getKey(), e.getValue());

Also, note I'm trying to avoid (relatively expensive) integer division,
except at compile time.

Nice.

Peter

Reply via email to