Skip to content

Commit

Permalink
Make proto functions internal for code size and speed
Browse files Browse the repository at this point in the history
  • Loading branch information
dsharlet committed Nov 20, 2024
1 parent 5623362 commit 730a347
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace proto {

namespace {

namespace internal {

constexpr size_t sum() { return 0; }
Expand Down Expand Up @@ -224,6 +226,8 @@ class buffer {
}
};

} // namespace

} // namespace proto

#endif // PTHREAD_TRACE_PROTO_H
11 changes: 9 additions & 2 deletions test/proto_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uint64_t decode_varint(const std::vector<uint8_t>& bytes) {
return result;
}

TEST(to_varint, basic) {
TEST(proto, to_varint) {
for (uint64_t i = 0; i <= 0x7f; ++i) {
ASSERT_EQ(to_varint(i), i);
}
Expand All @@ -41,7 +41,7 @@ std::vector<uint8_t> write_varint(uint64_t x) {
return result;
}

TEST(write_varint, basic) {
TEST(proto, write_varint) {
for (uint64_t i = 0; i <= 0x7f; ++i) {
ASSERT_THAT(write_varint(i), testing::ElementsAre(i));
}
Expand All @@ -60,4 +60,11 @@ TEST(write_varint, basic) {
ASSERT_EQ(decode_varint(varint), std::numeric_limits<uint64_t>::max());
}

TEST(proto, write_padding) {
std::array<uint8_t, 32> buffer;
for (uint64_t i = 0; i <= 0x7f; ++i) {
ASSERT_EQ(write_padding(buffer.data(), 0, i), i);
}
}

} // namespace proto

0 comments on commit 730a347

Please sign in to comment.