Ensure we succeed at constructing new sparse and dense arrays.

We could conceivably fail (in the presence of exceptions) to construct
the new dense array after constructing and replacing the sparse array.

Change-Id: I0fa0153c58e8b7de66aee464519a378b7f8c0bc8
Reviewed-on: https://code-review.googlesource.com/c/37291
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/util/sparse_set.h b/util/sparse_set.h
index efb9919..3cece2e 100644
--- a/util/sparse_set.h
+++ b/util/sparse_set.h
@@ -200,13 +200,12 @@
       std::copy_n(sparse_.data(), old_max_size, a.data());
     }
 
-    sparse_ = std::move(a);
-
     PODArray<int> b(max_size);
     if (dense_.data() != NULL) {
       std::copy_n(dense_.data(), old_max_size, b.data());
     }
 
+    sparse_ = std::move(a);
     dense_ = std::move(b);
 
     MaybeInitializeMemory(old_max_size, max_size);