unique_ptrify the AllocValueProfData helper function introduced in r252783
[oota-llvm.git] / lib / ProfileData / InstrProf.cpp
index ddd23014673af3ceabba41fcc5796de0d3ba451e..92a3c251f6ef806ddf24b6bb05d8caebaa3f5447 100644 (file)
@@ -244,17 +244,16 @@ void ValueProfData::deserializeTo(InstrProfRecord &Record,
   }
 }
 
-static ValueProfData *AllocValueProfData(uint32_t TotalSize) {
-  void *RawMem = ::operator new(TotalSize);
-  ValueProfData *VPDMem = new (RawMem) ValueProfData();
-  return VPDMem;
+static std::unique_ptr<ValueProfData> AllocValueProfData(uint32_t TotalSize) {
+  return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
+                                            ValueProfData());
 }
 
 std::unique_ptr<ValueProfData>
 ValueProfData::serializeFrom(const InstrProfRecord &Record) {
   uint32_t TotalSize = getSize(Record);
 
-  std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));
+  std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
 
   VPD->TotalSize = TotalSize;
   VPD->NumValueKinds = Record.getNumValueKinds();
@@ -290,7 +289,7 @@ ValueProfData::getValueProfData(const unsigned char *D,
   if (TotalSize % sizeof(uint64_t))
     return instrprof_error::malformed;
 
-  std::unique_ptr<ValueProfData> VPD(AllocValueProfData(TotalSize));
+  std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
 
   memcpy(VPD.get(), D, TotalSize);
   // Byte swap.