diff options
author | Amin Hassani <ahassani@google.com> | 2019-01-09 17:41:12 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-01-09 17:41:12 -0800 |
commit | bd56e58ee96fc7e075d397cdf9d7d73a6767d03c (patch) | |
tree | 07012e81ae848f56391188b1696b8be196c9cf23 | |
parent | 63bc20f6096f57ab8b8c596bacb850aacf967e11 (diff) | |
parent | 9f7909446e7550e006a05fba7ee88870fa8871b4 (diff) | |
download | platform_external_puffin-bd56e58ee96fc7e075d397cdf9d7d73a6767d03c.tar.gz platform_external_puffin-bd56e58ee96fc7e075d397cdf9d7d73a6767d03c.tar.bz2 platform_external_puffin-bd56e58ee96fc7e075d397cdf9d7d73a6767d03c.zip |
Do some spring house cleaning
am: 9f7909446e
Change-Id: Ib6917853b7b57a69cd1ced51d890b325cda9bd8d
-rw-r--r-- | src/huffman_table.cc | 9 | ||||
-rw-r--r-- | src/include/puffin/common.h | 2 | ||||
-rw-r--r-- | src/include/puffin/stream.h | 1 | ||||
-rw-r--r-- | src/main.cc | 5 | ||||
-rw-r--r-- | src/puffdiff.cc | 10 | ||||
-rw-r--r-- | src/puffin_stream.cc | 32 | ||||
-rw-r--r-- | src/puffin_stream.h | 10 | ||||
-rw-r--r-- | src/puffin_unittest.cc | 8 | ||||
-rw-r--r-- | src/puffpatch.cc | 5 | ||||
-rw-r--r-- | src/stream_unittest.cc | 5 | ||||
-rw-r--r-- | src/unittest_common.cc | 17 | ||||
-rw-r--r-- | src/utils.cc | 7 |
12 files changed, 56 insertions, 55 deletions
diff --git a/src/huffman_table.cc b/src/huffman_table.cc index 1aeaa45..3a12543 100644 --- a/src/huffman_table.cc +++ b/src/huffman_table.cc @@ -9,6 +9,9 @@ #include "puffin/src/logging.h" +using std::string; +using std::vector; + namespace puffin { // Permutations of input Huffman code lengths (used only to read code lengths @@ -105,7 +108,7 @@ bool HuffmanTable::InitHuffmanCodes(const Buffer& lens, size_t* max_bits) { } bool HuffmanTable::BuildHuffmanCodes(const Buffer& lens, - std::vector<uint16_t>* hcodes, + vector<uint16_t>* hcodes, size_t* max_bits) { TEST_AND_RETURN_FALSE(InitHuffmanCodes(lens, max_bits)); // Sort descending based on the bit-length of the code. @@ -132,7 +135,7 @@ bool HuffmanTable::BuildHuffmanCodes(const Buffer& lens, } bool HuffmanTable::BuildHuffmanReverseCodes(const Buffer& lens, - std::vector<uint16_t>* rcodes, + vector<uint16_t>* rcodes, size_t* max_bits) { TEST_AND_RETURN_FALSE(InitHuffmanCodes(lens, max_bits)); // Sort ascending based on the index. @@ -516,7 +519,7 @@ bool HuffmanTable::BuildHuffmanCodeLengths(const uint8_t* buffer, return true; } -std::string BlockTypeToString(BlockType type) { +string BlockTypeToString(BlockType type) { switch (type) { case BlockType::kUncompressed: return "Uncompressed"; diff --git a/src/include/puffin/common.h b/src/include/puffin/common.h index 4ead74d..2ab1db8 100644 --- a/src/include/puffin/common.h +++ b/src/include/puffin/common.h @@ -39,8 +39,6 @@ namespace puffin { using Buffer = std::vector<uint8_t>; -using UniqueBufferPtr = std::unique_ptr<Buffer>; -using SharedBufferPtr = std::shared_ptr<Buffer>; // This class is similar to the protobuf generated for |ProtoByteExtent|. We // defined an extra class so the users of puffin do not have to include diff --git a/src/include/puffin/stream.h b/src/include/puffin/stream.h index ada9d06..f480b59 100644 --- a/src/include/puffin/stream.h +++ b/src/include/puffin/stream.h @@ -40,7 +40,6 @@ class StreamInterface { }; using UniqueStreamPtr = std::unique_ptr<StreamInterface>; -using SharedStreamPtr = std::shared_ptr<StreamInterface>; } // namespace puffin diff --git a/src/main.cc b/src/main.cc index 12f823f..20f0948 100644 --- a/src/main.cc +++ b/src/main.cc @@ -36,6 +36,7 @@ using puffin::Puffer; using puffin::PuffinStream; using puffin::UniqueStreamPtr; using std::string; +using std::stringstream; using std::vector; namespace { @@ -47,10 +48,10 @@ template <typename T> vector<T> StringToExtents(const string& str) { vector<T> extents; if (!str.empty()) { - std::stringstream ss(str); + stringstream ss(str); string extent_str; while (getline(ss, extent_str, kExtentDelimeter)) { - std::stringstream extent_ss(extent_str); + stringstream extent_ss(extent_str); string offset_str, length_str; getline(extent_ss, offset_str, kOffsetLengthDelimeter); getline(extent_ss, length_str, kOffsetLengthDelimeter); diff --git a/src/puffdiff.cc b/src/puffdiff.cc index ac2458b..9e3de72 100644 --- a/src/puffdiff.cc +++ b/src/puffdiff.cc @@ -100,7 +100,7 @@ bool PuffDiff(UniqueStreamPtr src, UniqueStreamPtr dst, const vector<BitExtent>& src_deflates, const vector<BitExtent>& dst_deflates, - const std::vector<bsdiff::CompressorType>& compressors, + const vector<bsdiff::CompressorType>& compressors, const string& tmp_filepath, Buffer* patch) { auto puffer = std::make_shared<Puffer>(); @@ -153,10 +153,10 @@ bool PuffDiff(UniqueStreamPtr src, bool PuffDiff(const Buffer& src, const Buffer& dst, - const std::vector<BitExtent>& src_deflates, - const std::vector<BitExtent>& dst_deflates, - const std::vector<bsdiff::CompressorType>& compressors, - const std::string& tmp_filepath, + const vector<BitExtent>& src_deflates, + const vector<BitExtent>& dst_deflates, + const vector<bsdiff::CompressorType>& compressors, + const string& tmp_filepath, Buffer* patch) { return PuffDiff(MemoryStream::CreateForRead(src), MemoryStream::CreateForRead(dst), src_deflates, dst_deflates, diff --git a/src/puffin_stream.cc b/src/puffin_stream.cc index 91d0dd7..123f862 100644 --- a/src/puffin_stream.cc +++ b/src/puffin_stream.cc @@ -29,8 +29,8 @@ namespace puffin { namespace { bool CheckArgsIntegrity(uint64_t puff_size, - const std::vector<BitExtent>& deflates, - const std::vector<ByteExtent>& puffs) { + const vector<BitExtent>& deflates, + const vector<ByteExtent>& puffs) { TEST_AND_RETURN_FALSE(puffs.size() == deflates.size()); // Check if the |puff_size| is actually greater than the last byte of the last // puff in |puffs|. @@ -54,13 +54,12 @@ bool CheckArgsIntegrity(uint64_t puff_size, } // namespace -UniqueStreamPtr PuffinStream::CreateForPuff( - UniqueStreamPtr stream, - std::shared_ptr<Puffer> puffer, - uint64_t puff_size, - const std::vector<BitExtent>& deflates, - const std::vector<ByteExtent>& puffs, - size_t max_cache_size) { +UniqueStreamPtr PuffinStream::CreateForPuff(UniqueStreamPtr stream, + shared_ptr<Puffer> puffer, + uint64_t puff_size, + const vector<BitExtent>& deflates, + const vector<ByteExtent>& puffs, + size_t max_cache_size) { TEST_AND_RETURN_VALUE(CheckArgsIntegrity(puff_size, deflates, puffs), nullptr); TEST_AND_RETURN_VALUE(stream->Seek(0), nullptr); @@ -72,12 +71,11 @@ UniqueStreamPtr PuffinStream::CreateForPuff( return puffin_stream; } -UniqueStreamPtr PuffinStream::CreateForHuff( - UniqueStreamPtr stream, - std::shared_ptr<Huffer> huffer, - uint64_t puff_size, - const std::vector<BitExtent>& deflates, - const std::vector<ByteExtent>& puffs) { +UniqueStreamPtr PuffinStream::CreateForHuff(UniqueStreamPtr stream, + shared_ptr<Huffer> huffer, + uint64_t puff_size, + const vector<BitExtent>& deflates, + const vector<ByteExtent>& puffs) { TEST_AND_RETURN_VALUE(CheckArgsIntegrity(puff_size, deflates, puffs), nullptr); TEST_AND_RETURN_VALUE(stream->Seek(0), nullptr); @@ -441,10 +439,10 @@ bool PuffinStream::SetExtraByte() { bool PuffinStream::GetPuffCache(int puff_id, uint64_t puff_size, - SharedBufferPtr* buffer) { + shared_ptr<Buffer>* buffer) { bool found = false; // Search for it. - std::pair<int, SharedBufferPtr> cache; + std::pair<int, shared_ptr<Buffer>> cache; // TODO(*): Find a faster way of doing this? Maybe change the data structure // that supports faster search. for (auto iter = caches_.begin(); iter != caches_.end(); ++iter) { diff --git a/src/puffin_stream.h b/src/puffin_stream.h index 47b8ace..4baf067 100644 --- a/src/puffin_stream.h +++ b/src/puffin_stream.h @@ -102,7 +102,9 @@ class PuffinStream : public StreamInterface { // Returns the cache for the |puff_id|th puff. If it does not find it, either // returns the least accessed cached (if cache is full) or creates a new empty // buffer. It returns false if it cannot find the |puff_id|th puff cache. - bool GetPuffCache(int puff_id, uint64_t puff_size, SharedBufferPtr* buffer); + bool GetPuffCache(int puff_id, + uint64_t puff_size, + std::shared_ptr<Buffer>* buffer); UniqueStreamPtr stream_; @@ -149,11 +151,11 @@ class PuffinStream : public StreamInterface { // True if the |Close()| is called. bool closed_; - UniqueBufferPtr deflate_buffer_; - SharedBufferPtr puff_buffer_; + std::unique_ptr<Buffer> deflate_buffer_; + std::shared_ptr<Buffer> puff_buffer_; // The list of puff buffer caches. - std::list<std::pair<int, SharedBufferPtr>> caches_; + std::list<std::pair<int, std::shared_ptr<Buffer>>> caches_; // The maximum memory (in bytes) kept for caching puff buffers by an object of // this class. size_t max_cache_size_; diff --git a/src/puffin_unittest.cc b/src/puffin_unittest.cc index 322e97b..0279813 100644 --- a/src/puffin_unittest.cc +++ b/src/puffin_unittest.cc @@ -187,7 +187,7 @@ class PuffinTest : public ::testing::Test { const vector<BitExtent>& deflate_extents, const Buffer& puff_buffer, const vector<ByteExtent>& puff_extents) { - std::shared_ptr<Puffer> puffer(new Puffer()); + auto puffer = std::make_shared<Puffer>(); auto deflate_stream = MemoryStream::CreateForRead(deflate_buffer); ASSERT_TRUE(deflate_stream->Seek(0)); vector<ByteExtent> out_puff_extents; @@ -206,7 +206,7 @@ class PuffinTest : public ::testing::Test { out_puff_buffer.size())); EXPECT_EQ(out_puff_buffer, puff_buffer); - std::shared_ptr<Huffer> huffer(new Huffer()); + auto huffer = std::make_shared<Huffer>(); Buffer out_deflate_buffer; deflate_stream = MemoryStream::CreateForWrite(&out_deflate_buffer); @@ -560,11 +560,11 @@ const Buffer kGapPuffs = {0x00, 0x00, 0x20, 0x00, 0x01, 0xFF, 0x81, // puff 0 // The fifth deflate (and its puff in kGapPuffExtents) is for zero length // deflate corner case. -const std::vector<BitExtent> kGapSubblockDeflateExtents = { +const vector<BitExtent> kGapSubblockDeflateExtents = { {0, 18}, {18, 18}, {37, 18}, {57, 18}, {75, 0}, {78, 18}, {96, 18}, {122, 18}, {140, 18}, {166, 18}, {186, 18}, {206, 18}, {232, 18}}; -const std::vector<ByteExtent> kGapPuffExtents = { +const vector<ByteExtent> kGapPuffExtents = { {0, 7}, {7, 7}, {15, 7}, {24, 7}, {31, 0}, {32, 7}, {39, 7}, {48, 7}, {55, 7}, {64, 7}, {72, 7}, {80, 7}, {88, 7}}; } // namespace diff --git a/src/puffpatch.cc b/src/puffpatch.cc index 2dd3a29..0b4ffcb 100644 --- a/src/puffpatch.cc +++ b/src/puffpatch.cc @@ -24,6 +24,7 @@ #include "puffin/src/puffin_stream.h" using std::string; +using std::unique_ptr; using std::vector; namespace puffin { @@ -48,9 +49,9 @@ class BsdiffStream : public bsdiff::FileInterface { public: ~BsdiffStream() override = default; - static std::unique_ptr<bsdiff::FileInterface> Create(UniqueStreamPtr stream) { + static unique_ptr<bsdiff::FileInterface> Create(UniqueStreamPtr stream) { TEST_AND_RETURN_VALUE(stream, nullptr); - return std::unique_ptr<bsdiff::FileInterface>( + return unique_ptr<bsdiff::FileInterface>( new BsdiffStream(std::move(stream))); } diff --git a/src/stream_unittest.cc b/src/stream_unittest.cc index 76fe34b..5c1f984 100644 --- a/src/stream_unittest.cc +++ b/src/stream_unittest.cc @@ -14,7 +14,6 @@ #include "puffin/src/puffin_stream.h" #include "puffin/src/unittest_common.h" -using std::shared_ptr; using std::string; using std::vector; @@ -196,7 +195,7 @@ TEST_F(StreamTest, FileStreamTest) { } TEST_F(StreamTest, PuffinStreamTest) { - shared_ptr<Puffer> puffer(new Puffer()); + auto puffer = std::make_shared<Puffer>(); auto read_stream = PuffinStream::CreateForPuff( MemoryStream::CreateForRead(kDeflatesSample1), puffer, kPuffsSample1.size(), kSubblockDeflateExtentsSample1, @@ -215,7 +214,7 @@ TEST_F(StreamTest, PuffinStreamTest) { TestClose(read_stream.get()); Buffer buf(kDeflatesSample1.size()); - shared_ptr<Huffer> huffer(new Huffer()); + auto huffer = std::make_shared<Huffer>(); auto write_stream = PuffinStream::CreateForHuff( MemoryStream::CreateForWrite(&buf), huffer, kPuffsSample1.size(), kSubblockDeflateExtentsSample1, kPuffExtentsSample1); diff --git a/src/unittest_common.cc b/src/unittest_common.cc index 6bc3b1d..ad3a85f 100644 --- a/src/unittest_common.cc +++ b/src/unittest_common.cc @@ -5,6 +5,7 @@ #include "puffin/src/unittest_common.h" using std::string; +using std::vector; namespace puffin { @@ -47,11 +48,11 @@ const Buffer kPuffsSample1 = { /* puff 21 */ 0x00, 0x00, 0xA0, 0x00, 0x01, 0xFF, 0x81, /* raw 28 */ 0x00, 0x44, 0x55 }; -const std::vector<ByteExtent> kDeflateExtentsSample1 = { +const vector<ByteExtent> kDeflateExtentsSample1 = { {2, 7}, {10, 2}, {12, 3}}; -const std::vector<BitExtent> kSubblockDeflateExtentsSample1 = { +const vector<BitExtent> kSubblockDeflateExtentsSample1 = { {16, 50}, {80, 10}, {96, 18}}; -const std::vector<ByteExtent> kPuffExtentsSample1 = {{2, 11}, {15, 5}, {21, 7}}; +const vector<ByteExtent> kPuffExtentsSample1 = {{2, 11}, {15, 5}, {21, 7}}; const Buffer kDeflatesSample2 = { /* def 0 */ 0x63, 0x64, 0x62, 0x66, 0x61, 0x05, 0x00, @@ -68,11 +69,11 @@ const Buffer kPuffsSample2 = { /* puff 25 */ 0x00, 0x00, 0xA0, 0x00, 0x01, 0xFF, 0x81, /* raw 32 */ 0x00, }; -const std::vector<ByteExtent> kDeflateExtentsSample2 = { +const vector<ByteExtent> kDeflateExtentsSample2 = { {0, 7}, {9, 10}, {19, 3}}; -const std::vector<BitExtent> kSubblockDeflateExtentsSample2 = { +const vector<BitExtent> kSubblockDeflateExtentsSample2 = { {0, 50}, {72, 80}, {152, 18}}; -const std::vector<ByteExtent> kPuffExtentsSample2 = { +const vector<ByteExtent> kPuffExtentsSample2 = { {0, 11}, {14, 11}, {25, 7}}; // clang-format on @@ -85,7 +86,7 @@ const Buffer kProblematicCache = { 0x83, 0xbd, 0xff, 0xf3, 0xe1, 0xf8, 0x9d, 0xd7, 0xba, 0xd6, 0x9a, 0x7b, 0x86, 0x99, 0x3b, 0xf7, 0xbb, 0xdf, 0xfd, 0x90, 0xf0, 0x45, 0x0b, 0xb4, 0x44, 0x2b, 0xb4, 0x46, 0x1b, 0xb4, 0xc5, 0xff}; -const std::vector<BitExtent> kProblematicCacheDeflateExtents = {{2, 606}}; -const std::vector<BitExtent> kProblematicCachePuffExtents = {{1, 185}}; +const vector<BitExtent> kProblematicCacheDeflateExtents = {{2, 606}}; +const vector<BitExtent> kProblematicCachePuffExtents = {{1, 185}}; } // namespace puffin diff --git a/src/utils.cc b/src/utils.cc index 3ff4d64..708684d 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -95,8 +95,7 @@ bool LocateDeflatesInDeflateStream(const uint8_t* data, // the proper size of the zlib stream in |data|. Basically the size of the zlib // stream should be known before hand. Otherwise we need to parse the stream and // find the location of compressed blocks using CalculateSizeOfDeflateBlock(). -bool LocateDeflatesInZlib(const Buffer& data, - std::vector<BitExtent>* deflates) { +bool LocateDeflatesInZlib(const Buffer& data, vector<BitExtent>* deflates) { // A zlib stream has the following format: // 0 1 compression method and flag // 1 1 flag @@ -381,8 +380,8 @@ bool FindPuffLocations(const UniqueStreamPtr& src, void RemoveEqualBitExtents(const Buffer& data1, const Buffer& data2, - std::vector<BitExtent>* extents1, - std::vector<BitExtent>* extents2) { + vector<BitExtent>* extents1, + vector<BitExtent>* extents2) { set<ExtentData> extent1_set, equal_extents; for (const BitExtent& ext : *extents1) { extent1_set.emplace(ext, data1); |