Add writeAsHex(raw_ostream &) method to BinaryRef.

This hides the implementation. A future commit will remove the
error-prone getHex() and getBinary() methods.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183352 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Object/YAML.cpp b/lib/Object/YAML.cpp
index cf6e616..e63bd5d 100644
--- a/lib/Object/YAML.cpp
+++ b/lib/Object/YAML.cpp
@@ -20,13 +20,7 @@
 
 void yaml::ScalarTraits<object::yaml::BinaryRef>::output(
     const object::yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
-  ArrayRef<uint8_t> Data = Val.getBinary();
-  for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
-       ++I) {
-    uint8_t Byte = *I;
-    Out << hexdigit(Byte >> 4);
-    Out << hexdigit(Byte & 0xf);
-  }
+  Val.writeAsHex(Out);
 }
 
 // Can't find this anywhere else in the codebase (clang has one, but it has
@@ -61,3 +55,16 @@
     OS.write(Byte);
   }
 }
+
+void BinaryRef::writeAsHex(raw_ostream &OS) const {
+  if (DataIsHexString) {
+    OS.write((const char *)Data.data(), Data.size());
+    return;
+  }
+  for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
+       ++I) {
+    uint8_t Byte = *I;
+    OS << hexdigit(Byte >> 4);
+    OS << hexdigit(Byte & 0xf);
+  }
+}