aboutsummaryrefslogtreecommitdiff
path: root/types_test.cpp
diff options
context:
space:
mode:
authorYurii Zubrytskyi <zyy@google.com>2019-07-12 14:11:54 -0700
committerJosh Gao <jmgao@google.com>2019-11-28 18:24:01 -0800
commite5e6b0d89d8e2d9b32c0bd33298fe8de037b171b (patch)
treed29985efba87814160d22f646f3b3458a7c91a5c /types_test.cpp
parentdcea54ce982a0a757199340611365b608a54c6fe (diff)
downloadadb-e5e6b0d89d8e2d9b32c0bd33298fe8de037b171b.tar.gz
[adb] Optimize adbd's usb reading
Try to not allocate as many blocks on the heap, and reuse memory instead of copying it Get rid of unique_ptr and shared_ptr where possible, move the Block objects themselves Overall this reduces the time spent in memcpy() from 30% to 15% of the whole 'adb push' command, and gets rid of about 5% of the time spent in the malloc/free calls Test: builds Change-Id: I8995115274b6f08a4df13c58183c928ef384a767
Diffstat (limited to 'types_test.cpp')
-rw-r--r--types_test.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/types_test.cpp b/types_test.cpp
index 1fbd2ca2..2c99f951 100644
--- a/types_test.cpp
+++ b/types_test.cpp
@@ -19,21 +19,21 @@
#include <memory>
#include "types.h"
-static std::unique_ptr<IOVector::block_type> create_block(const std::string& string) {
- return std::make_unique<IOVector::block_type>(string.begin(), string.end());
+static IOVector::block_type create_block(const std::string& string) {
+ return IOVector::block_type(string.begin(), string.end());
}
-static std::unique_ptr<IOVector::block_type> create_block(char value, size_t len) {
- auto block = std::make_unique<IOVector::block_type>();
- block->resize(len);
- memset(&(*block)[0], value, len);
+static IOVector::block_type create_block(char value, size_t len) {
+ auto block = IOVector::block_type();
+ block.resize(len);
+ memset(&(block)[0], value, len);
return block;
}
template <typename T>
-static std::unique_ptr<IOVector::block_type> copy_block(T&& block) {
- auto copy = std::make_unique<IOVector::block_type>();
- copy->assign(block->begin(), block->end());
+static IOVector::block_type copy_block(const T& block) {
+ auto copy = IOVector::block_type();
+ copy.assign(block.begin(), block.end());
return copy;
}
@@ -50,7 +50,7 @@ TEST(IOVector, single_block) {
bc.append(copy_block(block));
ASSERT_EQ(100ULL, bc.size());
auto coalesced = bc.coalesce();
- ASSERT_EQ(*block, coalesced);
+ ASSERT_EQ(block, coalesced);
}
TEST(IOVector, single_block_split) {
@@ -60,8 +60,8 @@ TEST(IOVector, single_block_split) {
IOVector foo = bc.take_front(3);
ASSERT_EQ(3ULL, foo.size());
ASSERT_EQ(3ULL, bc.size());
- ASSERT_EQ(*create_block("foo"), foo.coalesce());
- ASSERT_EQ(*create_block("bar"), bc.coalesce());
+ ASSERT_EQ(create_block("foo"), foo.coalesce());
+ ASSERT_EQ(create_block("bar"), bc.coalesce());
}
TEST(IOVector, aligned_split) {
@@ -73,15 +73,15 @@ TEST(IOVector, aligned_split) {
IOVector foo = bc.take_front(3);
ASSERT_EQ(3ULL, foo.size());
- ASSERT_EQ(*create_block("foo"), foo.coalesce());
+ ASSERT_EQ(create_block("foo"), foo.coalesce());
IOVector bar = bc.take_front(3);
ASSERT_EQ(3ULL, bar.size());
- ASSERT_EQ(*create_block("bar"), bar.coalesce());
+ ASSERT_EQ(create_block("bar"), bar.coalesce());
IOVector baz = bc.take_front(3);
ASSERT_EQ(3ULL, baz.size());
- ASSERT_EQ(*create_block("baz"), baz.coalesce());
+ ASSERT_EQ(create_block("baz"), baz.coalesce());
ASSERT_EQ(0ULL, bc.size());
}
@@ -97,23 +97,23 @@ TEST(IOVector, misaligned_split) {
// Aligned left, misaligned right, across multiple blocks.
IOVector foob = bc.take_front(4);
ASSERT_EQ(4ULL, foob.size());
- ASSERT_EQ(*create_block("foob"), foob.coalesce());
+ ASSERT_EQ(create_block("foob"), foob.coalesce());
// Misaligned left, misaligned right, in one block.
IOVector a = bc.take_front(1);
ASSERT_EQ(1ULL, a.size());
- ASSERT_EQ(*create_block("a"), a.coalesce());
+ ASSERT_EQ(create_block("a"), a.coalesce());
// Misaligned left, misaligned right, across two blocks.
IOVector rba = bc.take_front(3);
ASSERT_EQ(3ULL, rba.size());
- ASSERT_EQ(*create_block("rba"), rba.coalesce());
+ ASSERT_EQ(create_block("rba"), rba.coalesce());
// Misaligned left, misaligned right, across three blocks.
IOVector zquxquu = bc.take_front(7);
ASSERT_EQ(7ULL, zquxquu.size());
- ASSERT_EQ(*create_block("zquxquu"), zquxquu.coalesce());
+ ASSERT_EQ(create_block("zquxquu"), zquxquu.coalesce());
ASSERT_EQ(1ULL, bc.size());
- ASSERT_EQ(*create_block("x"), bc.coalesce());
+ ASSERT_EQ(create_block("x"), bc.coalesce());
}