OSDN Git Service

Reserve space in the char backing vector to prevent reallocations
authorBen Gruver <bgruv@google.com>
Fri, 30 Sep 2016 20:10:42 +0000 (13:10 -0700)
committerBen Gruver <bgruv@google.com>
Fri, 30 Sep 2016 20:24:23 +0000 (13:24 -0700)
The pointers in image_filenames_ and oat_filenames can become invalidated
if the char_backing_storage_ vector gets reallocated when adding strings.

Test: mma test-art-host-gtest-dex2oat_test
Change-Id: I82714468163ce49ce53953e6edcb57a17d46cdbb

dex2oat/dex2oat.cc

index 5d44cc1..1ddf961 100644 (file)
@@ -990,6 +990,8 @@ class Dex2Oat FINAL {
       }
     }
 
+    char_backing_storage_.reserve((dex_locations_.size() - 1) * 2);
+
     // Now create the other names. Use a counted loop to skip the first one.
     for (size_t i = 1; i < dex_locations_.size(); ++i) {
       // TODO: Make everything properly std::string.