         (let [sub-node (aget arr (node-at arr nodemap bit))
               sub-node-new (.inode-without sub-node wedit (+ shift 5) hash key changed?)]
           (if (.-modified changed?)
-            (if (== 1 (bit-count nodemap))
-              (if (zero? datamap)
-                (.copy-and-migrate-to-inline inode wedit bit sub-node-new)
-                sub-node-new)
+            (if (.single-kv? sub-node-new)
+              (if (and (zero? datamap) (== 1 (bit-count nodemap)))
+                sub-node-new
+                (.copy-and-migrate-to-inline inode wedit bit sub-node-new))
               (.copy-and-set-node inode wedit bit sub-node-new))
             inode))
         :else

    (let [idx (hash-collision-node-find-index arr cnt key)]
      (cond (< idx 0)              not-found
            (key-test key (aget arr idx)) [(aget arr idx) (aget arr (inc idx))]
            :else                  not-found))))

(deftype PersistentHashMap [meta cnt root ^:mutable __hash]
  Object

          idx-new (* 2 (bitmap-indexed-node-index datamap bit))
          dst (make-array (inc (alength arr)))]
      (array-copy arr 0 dst 0 idx-new)
      (aset dst idx-new (aget (.-arr node) 0))
      (aset dst (inc idx-new) (aget (.-arr node) 1))
      (array-copy arr idx-new dst (+ idx-new 2) (- idx-old idx-new))
      (array-copy arr (inc idx-old) dst (+ idx-old 2) (- (alength arr) idx-old 1))
      (BitmapIndexedNode. e (bit-or datamap bit) (bit-xor nodemap bit) dst)))

  (single-kv? [_]
    (and (zero? nodemap) (== 1 (bit-count datamap))))

  (inode-without [inode wedit shift hash key changed?]
    (let [bit (bitpos hash shift)]
