Don't default-construct std::strings and then assign them.

Change-Id: I8c994d1e6a8d2ebe52eaa4f0132e0deb2ecfa5f3
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 88016f4..ab5f9d6e 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -696,7 +696,7 @@
     }
 
     // not found in /foo/bar/baz.oat? try /data/art-cache/foo@bar@baz.oat
-    std::string cache_location = GetArtCacheFilenameOrDie(oat_location);
+    std::string cache_location(GetArtCacheFilenameOrDie(oat_location));
     oat_file = FindOpenedOatFileFromOatLocation(cache_location);
     if (oat_file != NULL) {
       return oat_file;
@@ -739,7 +739,7 @@
                static_cast<uint32_t>(dex_caches->GetLength()));
       for (int i = 0; i < dex_caches->GetLength(); i++) {
         SirtRef<DexCache> dex_cache(dex_caches->Get(i));
-        const std::string& dex_file_location = dex_cache->GetLocation()->ToModifiedUtf8();
+        const std::string& dex_file_location(dex_cache->GetLocation()->ToModifiedUtf8());
 
         std::string dex_filename;
         dex_filename += runtime->GetHostPrefix();
@@ -1018,7 +1018,7 @@
     }
 
   } else {
-    std::string class_name_string = DescriptorToDot(descriptor);
+    std::string class_name_string(DescriptorToDot(descriptor));
     ScopedThreadStateChange(self, Thread::kNative);
     JNIEnv* env = self->GetJniEnv();
     ScopedLocalRef<jclass> c(env, AddLocalReference<jclass>(env, GetClassRoot(kJavaLangClassLoader)));
diff --git a/src/common_test.h b/src/common_test.h
index 48a9c39..5093976 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -297,7 +297,7 @@
   }
 
   const DexFile* GetLibCoreDex() {
-    std::string libcore_dex_file_name = GetLibCoreDexFileName();
+    std::string libcore_dex_file_name(GetLibCoreDexFileName());
     return DexFile::Open(libcore_dex_file_name, "");
   }
 
@@ -330,7 +330,7 @@
   }
 
   void CompileClass(const ClassLoader* class_loader, const char* class_name) {
-    std::string class_descriptor = DotToDescriptor(class_name);
+    std::string class_descriptor(DotToDescriptor(class_name));
     Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
     CHECK(klass != NULL) << "Class not found " << class_name;
     for (size_t i = 0; i < klass->NumDirectMethods(); i++) {
@@ -353,7 +353,7 @@
                            const char* class_name,
                            const char* method_name,
                            const char* signature) {
-    std::string class_descriptor = DotToDescriptor(class_name);
+    std::string class_descriptor(DotToDescriptor(class_name));
     Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
     CHECK(klass != NULL) << "Class not found " << class_name;
     Method* method = klass->FindDirectMethod(method_name, signature);
@@ -366,7 +366,7 @@
                             const char* class_name,
                             const char* method_name,
                             const char* signature) {
-    std::string class_descriptor = DotToDescriptor(class_name);
+    std::string class_descriptor(DotToDescriptor(class_name));
     Class* klass = class_linker_->FindClass(class_descriptor, class_loader);
     CHECK(klass != NULL) << "Class not found " << class_name;
     Method* method = klass->FindVirtualMethod(method_name, signature);
diff --git a/src/compiler.cc b/src/compiler.cc
index 7ed953b..e01ab74 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -439,7 +439,7 @@
 }
 
 const CompiledInvokeStub* Compiler::FindInvokeStub(bool is_static, const char* shorty) const {
-  const std::string key = MakeInvokeStubKey(is_static, shorty);
+  const std::string key(MakeInvokeStubKey(is_static, shorty));
   InvokeStubTable::const_iterator it = compiled_invoke_stubs_.find(key);
   if (it == compiled_invoke_stubs_.end()) {
     return NULL;
@@ -451,7 +451,7 @@
 
 void Compiler::InsertInvokeStub(bool is_static, const char* shorty,
                                 const CompiledInvokeStub* compiled_invoke_stub) {
-  std::string key = MakeInvokeStubKey(is_static, shorty);
+  std::string key(MakeInvokeStubKey(is_static, shorty));
   compiled_invoke_stubs_[key] = compiled_invoke_stub;
 }
 
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index 75f5d7d..ba5bd3d 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -215,7 +215,7 @@
 void oatDumpCFG(CompilationUnit* cUnit, const char* dirPrefix)
 {
     FILE* file;
-    std::string name = art::PrettyMethod(cUnit->method_idx, *cUnit->dex_file);
+    std::string name(art::PrettyMethod(cUnit->method_idx, *cUnit->dex_file));
     char startOffset[80];
     sprintf(startOffset, "_%x", cUnit->entryBlock->fallThrough->startOffset);
     char* fileName = (char*) oatNew(
diff --git a/src/compiler/codegen/arm/ArchUtility.cc b/src/compiler/codegen/arm/ArchUtility.cc
index b702682..52fb018 100644
--- a/src/compiler/codegen/arm/ArchUtility.cc
+++ b/src/compiler/codegen/arm/ArchUtility.cc
@@ -449,10 +449,9 @@
 
     const art::DexFile::MethodId& method_id =
         cUnit->dex_file->GetMethodId(cUnit->method_idx);
-    std::string signature = cUnit->dex_file->GetMethodSignature(method_id);
-    std::string name = cUnit->dex_file->GetMethodName(method_id);
-    std::string descriptor =
-        cUnit->dex_file->GetMethodDeclaringClassDescriptor(method_id);
+    std::string signature(cUnit->dex_file->GetMethodSignature(method_id));
+    std::string name(cUnit->dex_file->GetMethodName(method_id));
+    std::string descriptor(cUnit->dex_file->GetMethodDeclaringClassDescriptor(method_id));
 
     // Dump mapping table
     if (cUnit->mappingTable.size() > 0) {
diff --git a/src/compiler/codegen/arm/Thumb2/Gen.cc b/src/compiler/codegen/arm/Thumb2/Gen.cc
index b02cde5..6796f6c 100644
--- a/src/compiler/codegen/arm/Thumb2/Gen.cc
+++ b/src/compiler/codegen/arm/Thumb2/Gen.cc
@@ -36,10 +36,10 @@
 void warnIfUnresolved(CompilationUnit* cUnit, int fieldIdx, Field* field) {
   if (field == NULL) {
     const art::DexFile::FieldId& field_id = cUnit->dex_file->GetFieldId(fieldIdx);
-    std::string class_name = cUnit->dex_file->GetFieldDeclaringClassDescriptor(field_id);
-    std::string field_name = cUnit->dex_file->GetFieldName(field_id);
-    LOG(INFO) << "Field " << art::PrettyDescriptor(class_name) << "."
-        << field_name << " unresolved at compile time";
+    std::string class_name(cUnit->dex_file->GetFieldDeclaringClassDescriptor(field_id));
+    std::string field_name(cUnit->dex_file->GetFieldName(field_id));
+    LOG(INFO) << "Field " << art::PrettyDescriptor(class_name) << "." << field_name
+              << " unresolved at compile time";
   } else {
     // We also use the slow path for wide volatile fields.
   }
diff --git a/src/dalvik_system_DexFile.cc b/src/dalvik_system_DexFile.cc
index cf4443b..f668cc9 100644
--- a/src/dalvik_system_DexFile.cc
+++ b/src/dalvik_system_DexFile.cc
@@ -163,7 +163,7 @@
   if (class_name.c_str() == NULL) {
     return NULL;
   }
-  const std::string descriptor = DotToDescriptor(class_name.c_str());
+  const std::string descriptor(DotToDescriptor(class_name.c_str()));
   const DexFile::ClassDef* dex_class_def = dex_file->FindClassDef(descriptor);
   if (dex_class_def == NULL) {
     return NULL;
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index 4f11add..da07dbd 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -98,7 +98,7 @@
       if (StringPiece(dot).starts_with("#") || dot.empty()) {
         continue;
       }
-      std::string descriptor = DotToDescriptor(dot.c_str());
+      std::string descriptor(DotToDescriptor(dot.c_str()));
       SirtRef<Class> klass(class_linker->FindSystemClass(descriptor));
       if (klass.get() == NULL) {
         LOG(WARNING) << "Failed to find class " << descriptor;
diff --git a/src/dex_file.cc b/src/dex_file.cc
index b92760b..ce7dde6 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -218,7 +218,7 @@
     return NULL;
   }
 
-  std::string cache_path = StringPrintf("%s.%08x", cache_path_tmp.c_str(), zip_entry->GetCrc32());
+  std::string cache_path(StringPrintf("%s.%08x", cache_path_tmp.c_str(), zip_entry->GetCrc32()));
   // Example cache_path = /data/art-cache/parent@dir@foo.jar@classes.dex.1a2b3c4d
 
   bool created = false;
diff --git a/src/dex_verifier.cc b/src/dex_verifier.cc
index 9ba5d34..36c9d38 100644
--- a/src/dex_verifier.cc
+++ b/src/dex_verifier.cc
@@ -125,7 +125,7 @@
     Class* common_elem = ClassJoin(s_ct, t_ct);
     ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
     const ClassLoader* class_loader = s->GetClassLoader();
-    std::string descriptor = "[";
+    std::string descriptor("[");
     descriptor += ClassHelper(common_elem).GetDescriptor();
     Class* array_class = class_linker->FindClass(descriptor.c_str(), class_loader);
     DCHECK(array_class != NULL);
@@ -523,8 +523,8 @@
 const RegType& RegTypeCache::GetComponentType(const RegType& array, const ClassLoader* loader) {
   CHECK(array.IsArrayClass());
   if (array.IsUnresolvedTypes()) {
-    std::string descriptor = array.GetDescriptor()->ToModifiedUtf8();
-    std::string component = descriptor.substr(1, descriptor.size() - 1);
+    std::string descriptor(array.GetDescriptor()->ToModifiedUtf8());
+    std::string component(descriptor.substr(1, descriptor.size() - 1));
     return FromDescriptor(loader, component);
   } else {
     return FromClass(array.GetClass()->GetComponentType());
diff --git a/src/file_test.cc b/src/file_test.cc
index 99e4b41..2c91ab6 100644
--- a/src/file_test.cc
+++ b/src/file_test.cc
@@ -11,7 +11,7 @@
 class FileTest : public CommonTest {};
 
 TEST_F(FileTest, Read) {
-  std::string filename = GetLibCoreDexFileName();
+  std::string filename(GetLibCoreDexFileName());
   UniquePtr<File> file(OS::OpenFile(filename.c_str(), false));
   ASSERT_TRUE(file.get() != NULL);
   EXPECT_STREQ(filename.c_str(), file->name());
@@ -25,7 +25,7 @@
 
 
 TEST_F(FileTest, FileLength) {
-  std::string filename = GetLibCoreDexFileName();
+  std::string filename(GetLibCoreDexFileName());
   UniquePtr<File> file(OS::OpenFile(filename.c_str(), false));
   ASSERT_TRUE(file.get() != NULL);
   EXPECT_NE(0, file->Length());
@@ -33,7 +33,7 @@
 
 
 TEST_F(FileTest, FilePosition) {
-  std::string filename = GetLibCoreDexFileName();
+  std::string filename(GetLibCoreDexFileName());
   UniquePtr<File> file(OS::OpenFile(filename.c_str(), false));
   ASSERT_TRUE(file.get() != NULL);
   char buf[4];
@@ -45,7 +45,7 @@
 
 
 TEST_F(FileTest, FileFd) {
-  std::string filename = GetLibCoreDexFileName();
+  std::string filename(GetLibCoreDexFileName());
   UniquePtr<File> file(OS::OpenFile(filename.c_str(), false));
   ASSERT_TRUE(file.get() != NULL);
   EXPECT_NE(-1, file->Fd());
diff --git a/src/hprof/hprof.cc b/src/hprof/hprof.cc
index 64cd7db..c90ccf0 100644
--- a/src/hprof/hprof.cc
+++ b/src/hprof/hprof.cc
@@ -660,7 +660,7 @@
   HprofRecord *rec = &current_record_;
 
   for (StringMapIterator it = strings_.begin(); it != strings_.end(); ++it) {
-    std::string string = (*it).first;
+    std::string string((*it).first);
     size_t id = (*it).second;
 
     int err = StartNewRecord(HPROF_TAG_STRING, HPROF_TIME);
diff --git a/src/java_lang_Class.cc b/src/java_lang_Class.cc
index 92fb6fa..e36e5db 100644
--- a/src/java_lang_Class.cc
+++ b/src/java_lang_Class.cc
@@ -261,7 +261,7 @@
 jobject Class_getDeclaredConstructorOrMethod(JNIEnv* env, jclass javaClass, jstring javaName,
                                              jobjectArray javaArgs) {
   Class* c = Decode<Class*>(env, javaClass);
-  std::string name = Decode<String*>(env, javaName)->ToModifiedUtf8();
+  std::string name(Decode<String*>(env, javaName)->ToModifiedUtf8());
   ObjectArray<Class>* arg_array = Decode<ObjectArray<Class>*>(env, javaArgs);
 
   Method* m = FindConstructorOrMethodInArray(c->GetDirectMethods(), name, arg_array);
diff --git a/src/mem_map.cc b/src/mem_map.cc
index 0d014c2..c5858c1 100644
--- a/src/mem_map.cc
+++ b/src/mem_map.cc
@@ -86,8 +86,8 @@
     if (remaining < 8+1+8) {  // 00008000-0001f000
       LOG(FATAL) << "Failed to parse at pos " << i << "\n" << maps;
     }
-    std::string start_str = maps.substr(i, 8);
-    std::string end_str = maps.substr(i+1+8, 8);
+    std::string start_str(maps.substr(i, 8));
+    std::string end_str(maps.substr(i+1+8, 8));
     uint32_t start = ParseHex(start_str);
     uint32_t end = ParseHex(end_str);
     CHECK(!(base >= start && base < end)       // start of new within old
diff --git a/src/oat_file.cc b/src/oat_file.cc
index 4804864..472a20c 100644
--- a/src/oat_file.cc
+++ b/src/oat_file.cc
@@ -12,7 +12,7 @@
 
 std::string OatFile::DexFilenameToOatFilename(const std::string& location) {
   CHECK(IsValidDexFilename(location) || IsValidZipFilename(location));
-  std::string oat_location = location.substr(0, location.size()-3);
+  std::string oat_location(location.substr(0, location.size() - 3));
   oat_location += "oat";
   return oat_location;
 }
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index f3e78e6..32ba4b1 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -601,7 +601,7 @@
 }
 
 OatWriter::OatDexFile::OatDexFile(const DexFile& dex_file) {
-  const std::string& location = dex_file.GetLocation();
+  const std::string& location(dex_file.GetLocation());
   dex_file_location_size_ = location.size();
   dex_file_location_data_ = reinterpret_cast<const uint8_t*>(location.data());
   dex_file_checksum_ = dex_file.GetHeader().checksum_;
diff --git a/src/oatdump.cc b/src/oatdump.cc
index 5cff2ea..2006827 100644
--- a/src/oatdump.cc
+++ b/src/oatdump.cc
@@ -106,7 +106,7 @@
                              const OatFile& oat_file,
                              const OatFile::OatDexFile& oat_dex_file) {
     os << "OAT DEX FILE:\n";
-    std::string dex_file_location = oat_dex_file.GetDexFileLocation();
+    std::string dex_file_location(oat_dex_file.GetDexFileLocation());
     os << "location: " << dex_file_location;
     if (!host_prefix.empty()) {
       dex_file_location = host_prefix + dex_file_location;
@@ -174,7 +174,7 @@
                             uint32_t method_idx) {
     const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx);
     const char* name = dex_file.GetMethodName(method_id);
-    std::string signature = dex_file.GetMethodSignature(method_id);
+    std::string signature(dex_file.GetMethodSignature(method_id));
     os << StringPrintf("\t%d: %s %s (method_idx=%d)\n",
                        method_index, name, signature.c_str(), method_idx);
     os << StringPrintf("\t\tcode: %p (offset=%08x)\n",
@@ -257,7 +257,7 @@
 
     os << "OAT LOCATION:\n" << std::flush;
     Object* oat_location_object = image_header.GetImageRoot(ImageHeader::kOatLocation);
-    std::string oat_location = oat_location_object->AsString()->ToModifiedUtf8();
+    std::string oat_location(oat_location_object->AsString()->ToModifiedUtf8());
     ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
     os << oat_location;
     if (!host_prefix.empty()) {
@@ -436,7 +436,7 @@
       size_t object_bytes_total = 0;
       typedef TableBytes::const_iterator It;  // TODO: C++0x auto
       for (It it = descriptor_to_bytes.begin(), end = descriptor_to_bytes.end(); it != end; ++it) {
-        const std::string& descriptor = it->first;
+        const std::string& descriptor(it->first);
         size_t bytes = it->second;
         size_t count = descriptor_to_count[descriptor];
         double average = static_cast<double>(bytes) / static_cast<double>(count);
diff --git a/src/object.cc b/src/object.cc
index 9e84327..1ef7201 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -800,9 +800,9 @@
   }
   // Compare the package part of the descriptor string.
   ClassHelper kh(klass1);
-  std::string descriptor1 = kh.GetDescriptor();
+  std::string descriptor1(kh.GetDescriptor());
   kh.ChangeClass(klass2);
-  std::string descriptor2 = kh.GetDescriptor();
+  std::string descriptor2(kh.GetDescriptor());
   return IsInSamePackage(descriptor1, descriptor2);
 }
 
diff --git a/src/object_utils.h b/src/object_utils.h
index f323190..c086fb8 100644
--- a/src/object_utils.h
+++ b/src/object_utils.h
@@ -52,7 +52,7 @@
 
   std::string GetDescriptor() {
     if (klass_->IsArrayClass()) {
-      std::string result = "[";
+      std::string result("[");
       const Class* saved_klass = klass_;
       ChangeClass(klass_->GetComponentType());
       result += GetDescriptor();
@@ -118,7 +118,7 @@
     }
   }
   const char* GetSourceFile() {
-    std::string descriptor = GetDescriptor();
+    std::string descriptor(GetDescriptor());
     const DexFile& dex_file = GetDexFile();
     const DexFile::ClassDef* dex_class_def = dex_file.FindClassDef(descriptor);
     if (dex_class_def == NULL) {
diff --git a/src/reflection.cc b/src/reflection.cc
index a6ae096..46b2ff3 100644
--- a/src/reflection.cc
+++ b/src/reflection.cc
@@ -305,7 +305,7 @@
   }
 
   JValue boxed_value = { 0 };
-  std::string src_descriptor = ClassHelper(o->GetClass()).GetDescriptor();
+  std::string src_descriptor(ClassHelper(o->GetClass()).GetDescriptor());
   Class* src_class = NULL;
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   Field* primitive_field = o->GetClass()->GetIFields()->Get(0);
diff --git a/src/runtime.cc b/src/runtime.cc
index 1304787..ad86e05 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -278,7 +278,7 @@
     } else if (option.starts_with("-Xcheck:jni")) {
       parsed->check_jni_ = true;
     } else if (option.starts_with("-Xrunjdwp:") || option.starts_with("-agentlib:jdwp=")) {
-      std::string tail = option.substr(option[1] == 'X' ? 10 : 15).ToString();
+      std::string tail(option.substr(option[1] == 'X' ? 10 : 15).ToString());
       if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
         LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
                    << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n";
diff --git a/src/runtime_test.cc b/src/runtime_test.cc
index 213897f..a926a23 100644
--- a/src/runtime_test.cc
+++ b/src/runtime_test.cc
@@ -15,7 +15,7 @@
   void* test_exit = reinterpret_cast<void*>(0xc);
   void* null = reinterpret_cast<void*>(NULL);
 
-  std::string lib_core = GetLibCoreDexFileName();
+  std::string lib_core(GetLibCoreDexFileName());
 
   std::string boot_class_path;
   boot_class_path += "-Xbootclasspath:";
diff --git a/src/thread.cc b/src/thread.cc
index fdfbf31..741727c 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -1304,7 +1304,7 @@
 void Thread::DumpFromGdb() const {
   std::ostringstream ss;
   Dump(ss);
-  std::string str = ss.str();
+  std::string str(ss.str());
   // log to stderr for debugging command line processes
   std::cerr << str;
 #ifdef HAVE_ANDROID_OS
diff --git a/src/utils.cc b/src/utils.cc
index 943899d..24e0429 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -260,7 +260,7 @@
 std::string DescriptorToDot(const std::string& descriptor) {
   DCHECK_EQ(descriptor[0], 'L');
   DCHECK_EQ(descriptor[descriptor.size()-1], ';');
-  std::string dot = descriptor.substr(1, descriptor.size()-2);
+  std::string dot(descriptor.substr(1, descriptor.size() - 2));
   std::replace(dot.begin(), dot.end(), '/', '.');
   return dot;
 }
@@ -571,7 +571,7 @@
     return "";
   }
 
-  std::string art_cache = StringPrintf("%s/art-cache", data_root);
+  std::string art_cache(StringPrintf("%s/art-cache", data_root));
 
   if (!OS::DirectoryExists(art_cache.c_str())) {
     if (StringPiece(art_cache).starts_with("/tmp/")) {
@@ -589,7 +589,7 @@
 }
 
 std::string GetArtCacheFilenameOrDie(const std::string& location) {
-  std::string art_cache = GetArtCacheOrDie();
+  std::string art_cache(GetArtCacheOrDie());
   CHECK_EQ(location[0], '/');
   std::string cache_file(location, 1); // skip leading slash
   std::replace(cache_file.begin(), cache_file.end(), '/', '@');