BitcodeWriter: Restructure WriteFunctionLocalMetadata, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 27 Mar 2016 23:38:36 +0000 (23:38 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sun, 27 Mar 2016 23:38:36 +0000 (23:38 +0000)
Use an early return to simplify logic.

llvm-svn: 264554

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

index 08724bd..e173d80 100644 (file)
@@ -1429,19 +1429,17 @@ static void WriteModuleMetadata(const Module &M,
 static void WriteFunctionLocalMetadata(const Function &F,
                                        const ValueEnumerator &VE,
                                        BitstreamWriter &Stream) {
-  bool StartedMetadataBlock = false;
+  ArrayRef<const Metadata *> MDs = VE.getFunctionMDs();
+  if (MDs.empty())
+    return;
+
+  Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+
   SmallVector<uint64_t, 64> Record;
-  for (const Metadata *MD : VE.getFunctionMDs()) {
-    auto *Local = cast<LocalAsMetadata>(MD);
-    if (!StartedMetadataBlock) {
-      Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
-      StartedMetadataBlock = true;
-    }
-    WriteValueAsMetadata(Local, VE, Stream, Record);
-  }
+  for (const Metadata *MD : VE.getFunctionMDs())
+    WriteValueAsMetadata(cast<LocalAsMetadata>(MD), VE, Stream, Record);
 
-  if (StartedMetadataBlock)
-    Stream.ExitBlock();
+  Stream.ExitBlock();
 }
 
 static void WriteMetadataAttachment(const Function &F,