Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Host / macosx / cfcpp / CFCData.cpp
blob6261a3a8b07edf4a39b0989be3311b186a3ce283
1 //===-- CFCData.cpp -------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "CFCData.h"
11 // CFCData constructor
12 CFCData::CFCData(CFDataRef data) : CFCReleaser<CFDataRef>(data) {}
14 // CFCData copy constructor
15 CFCData::CFCData(const CFCData &rhs) = default;
17 // CFCData copy constructor
18 CFCData &CFCData::operator=(const CFCData &rhs)
21 if (this != &rhs)
22 *this = rhs;
23 return *this;
26 // Destructor
27 CFCData::~CFCData() = default;
29 CFIndex CFCData::GetLength() const {
30 CFDataRef data = get();
31 if (data)
32 return CFDataGetLength(data);
33 return 0;
36 const uint8_t *CFCData::GetBytePtr() const {
37 CFDataRef data = get();
38 if (data)
39 return CFDataGetBytePtr(data);
40 return NULL;
43 CFDataRef CFCData::Serialize(CFPropertyListRef plist,
44 CFPropertyListFormat format) {
45 CFAllocatorRef alloc = kCFAllocatorDefault;
46 reset();
47 CFCReleaser<CFWriteStreamRef> stream(
48 ::CFWriteStreamCreateWithAllocatedBuffers(alloc, alloc));
49 ::CFWriteStreamOpen(stream.get());
50 CFIndex len = ::CFPropertyListWrite(plist, stream.get(), format, 0, nullptr);
51 if (len > 0)
52 reset((CFDataRef)::CFWriteStreamCopyProperty(stream.get(),
53 kCFStreamPropertyDataWritten));
54 ::CFWriteStreamClose(stream.get());
55 return get();