]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: split advanceEvacuationMark from evacuate
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 17 Aug 2017 17:37:17 +0000 (10:37 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 18 Aug 2017 18:20:55 +0000 (18:20 +0000)
Minor refactoring. This is a step towards specializing evacuate
for mapfast key types.

Change-Id: Icffe2759b7d38e5c008d03941918d5a912ce62f6
Reviewed-on: https://go-review.googlesource.com/56933
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/hashmap.go

index dcaab8c185995c0f1f3883926f008325fbbd7a87..f53f7087d8e50253743d1f184d9747a8a6a62fd2 100644 (file)
@@ -1138,29 +1138,32 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
                }
        }
 
-       // Advance evacuation mark
        if oldbucket == h.nevacuate {
+               advanceEvacuationMark(h, t, newbit)
+       }
+}
+
+func advanceEvacuationMark(h *hmap, t *maptype, newbit uintptr) {
+       h.nevacuate++
+       // Experiments suggest that 1024 is overkill by at least an order of magnitude.
+       // Put it in there as a safeguard anyway, to ensure O(1) behavior.
+       stop := h.nevacuate + 1024
+       if stop > newbit {
+               stop = newbit
+       }
+       for h.nevacuate != stop && bucketEvacuated(t, h, h.nevacuate) {
                h.nevacuate++
-               // Experiments suggest that 1024 is overkill by at least an order of magnitude.
-               // Put it in there as a safeguard anyway, to ensure O(1) behavior.
-               stop := h.nevacuate + 1024
-               if stop > newbit {
-                       stop = newbit
-               }
-               for h.nevacuate != stop && bucketEvacuated(t, h, h.nevacuate) {
-                       h.nevacuate++
-               }
-               if h.nevacuate == newbit { // newbit == # of oldbuckets
-                       // Growing is all done. Free old main bucket array.
-                       h.oldbuckets = nil
-                       // Can discard old overflow buckets as well.
-                       // If they are still referenced by an iterator,
-                       // then the iterator holds a pointers to the slice.
-                       if h.extra != nil {
-                               h.extra.overflow[1] = nil
-                       }
-                       h.flags &^= sameSizeGrow
+       }
+       if h.nevacuate == newbit { // newbit == # of oldbuckets
+               // Growing is all done. Free old main bucket array.
+               h.oldbuckets = nil
+               // Can discard old overflow buckets as well.
+               // If they are still referenced by an iterator,
+               // then the iterator holds a pointers to the slice.
+               if h.extra != nil {
+                       h.extra.overflow[1] = nil
                }
+               h.flags &^= sameSizeGrow
        }
 }