fr::Packet optimisations & marking Sendable::send() as const

Replaced instances of resize&memcpy with append, which gives a noticeable performance boost.

fr::Packet::operator<<(const char *str) no longer converts str into an std::string before adding it, removing an unneeded copy.

fr::Packet::clear no longer calls erase, should result in more of the internal buffer remaining allocated.

Framing for std::vector's has been changed from a uint64_t to a uint32_t (breaking change for packet framing!)
This commit is contained in:
Fred Nicolson
2018-03-27 12:03:55 +01:00
parent c0d103da14
commit 27d02ca055
11 changed files with 67 additions and 81 deletions
+8 -7
View File
@@ -15,13 +15,14 @@ enum Enum : uint32_t
E2 = 1,
E3 = 2,
};
size_t get_vector_size(const std::vector<int> &vec)
{
return vec.size();
}
int main()
{
fr::Packet packet;
std::vector<std::pair<int, int>> bob = {{1, 2}, {3, 4}};
packet << bob;
bob.clear();
packet >> bob;
std::cout << bob[0].first << ", " << bob[0].second << ", " << bob[1].first << ", " << bob[1].second << std::endl;
std::vector<int> source{1, 2, 3};
std::cout << get_vector_size(source) << std::endl;
}