Avoid some string allocations.

Also avoid building a string one character at a time.

Change-Id: I3db26226c620a730b95637d5bfc23e2d4715cfb9
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index b9df1d6..7b42879 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -697,11 +697,11 @@
   ScopedObjectAccess soa(self);
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   for (auto it = image_classes_->begin(), end = image_classes_->end(); it != end;) {
-    std::string descriptor(*it);
+    const std::string& descriptor(*it);
     SirtRef<mirror::Class> klass(self, class_linker->FindSystemClass(descriptor.c_str()));
     if (klass.get() == NULL) {
-      image_classes_->erase(it++);
       VLOG(compiler) << "Failed to find class " << descriptor;
+      image_classes_->erase(it++);
       self->ClearException();
     } else {
       ++it;
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 0ddcdf3..a7575ce 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -555,22 +555,19 @@
   size_t end = signature.size();
   bool process_return = false;
   while (offset < end) {
+    size_t start_offset = offset;
     char c = signature[offset];
     offset++;
     if (c == ')') {
       process_return = true;
       continue;
     }
-    // TODO: avoid building a string.
-    std::string descriptor;
-    descriptor += c;
     while (c == '[') {  // process array prefix
       if (offset >= end) {  // expect some descriptor following [
         return false;
       }
       c = signature[offset];
       offset++;
-      descriptor += c;
     }
     if (c == 'L') {  // process type descriptors
       do {
@@ -579,9 +576,10 @@
         }
         c = signature[offset];
         offset++;
-        descriptor += c;
       } while (c != ';');
     }
+    // TODO: avoid creating a std::string just to get a 0-terminated char array
+    std::string descriptor(signature.data() + start_offset, offset - start_offset);
     const DexFile::StringId* string_id = FindStringId(descriptor.c_str());
     if (string_id == NULL) {
       return false;
diff --git a/runtime/hprof/hprof.cc b/runtime/hprof/hprof.cc
index 67620a0..9f899e8 100644
--- a/runtime/hprof/hprof.cc
+++ b/runtime/hprof/hprof.cc
@@ -537,7 +537,7 @@
     HprofRecord* rec = &current_record_;
 
     for (StringMapIterator it = strings_.begin(); it != strings_.end(); ++it) {
-      std::string string((*it).first);
+      const std::string& string = (*it).first;
       size_t id = (*it).second;
 
       int err = current_record_.StartNewRecord(header_fp_, HPROF_TAG_STRING, HPROF_TIME);