Index: components/tracing/core/proto_zero_message.h |
diff --git a/components/tracing/core/proto_zero_message.h b/components/tracing/core/proto_zero_message.h |
index b5b0a37cce1bc4b82788c62108ee7036702cb6d0..ecf6cec747378891dcc5dd7bebc4ade2634afb7a 100644 |
--- a/components/tracing/core/proto_zero_message.h |
+++ b/components/tracing/core/proto_zero_message.h |
@@ -7,6 +7,7 @@ |
#include <stdint.h> |
+#include <set> |
#include <type_traits> |
#include "base/compiler_specific.h" |
@@ -62,7 +63,7 @@ class TRACING_EXPORT ProtoZeroMessage { |
protected: |
ProtoZeroMessage(); |
- // Proto types: uint64, uint32, int64, int32, bool, enum. |
+ // Proto types: uint64, uint32, int64, int32, enum (large). |
template <typename T> |
void AppendVarInt(uint32_t field_id, T value) { |
if (nested_message_) |
@@ -83,6 +84,21 @@ class TRACING_EXPORT ProtoZeroMessage { |
AppendVarInt(field_id, proto::ZigZagEncode(value)); |
} |
+ // Proto types: bool, enum (small). |
+ // Faster version of AppendVarInt for tiny numbers. |
+ void AppendTinyVarInt(uint32_t field_id, int32_t value) { |
+ DCHECK(0 <= value && value < 0x80); |
+ if (nested_message_) |
+ EndNestedMessage(); |
+ |
+ uint8_t buffer[proto::kMaxSimpleFieldEncodedSize]; |
+ uint8_t* pos = buffer; |
+ // MakeTagVarInt gets super optimized here for constexpr. |
+ pos = proto::WriteVarInt(proto::MakeTagVarInt(field_id), pos); |
+ *pos++ = static_cast<uint8_t>(value); |
+ WriteToStream(buffer, pos); |
+ } |
+ |
// Proto types: fixed64, sfixed64, fixed32, sfixed32, double, float. |
template <typename T> |
void AppendFixed(uint32_t field_id, T value) { |
@@ -99,7 +115,6 @@ class TRACING_EXPORT ProtoZeroMessage { |
WriteToStream(buffer, pos); |
} |
- // TODO(kraynov): Add AppendTinyInt. |
void AppendString(uint32_t field_id, const char* str); |
void AppendBytes(uint32_t field_id, const void* value, size_t size); |