Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: components/sync/protocol/proto_memory_estimations.cc

Issue 2875203002: UserEvent proto exploration for Translate use case. (Closed)
Patch Set: Adding proto_visitors.h change. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Keep this file in sync with the .proto files in this directory. 5 // Keep this file in sync with the .proto files in this directory.
6 6
7 #include "components/sync/protocol/proto_memory_estimations.h" 7 #include "components/sync/protocol/proto_memory_estimations.h"
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 29 matching lines...) Expand all
40 // Types derived from MessageLite (i.e. protos) 40 // Types derived from MessageLite (i.e. protos)
41 template <class P, class F> 41 template <class P, class F>
42 typename std::enable_if< 42 typename std::enable_if<
43 std::is_base_of<google::protobuf::MessageLite, F>::value>::type 43 std::is_base_of<google::protobuf::MessageLite, F>::value>::type
44 Visit(const P&, const char* field_name, const F& field) { 44 Visit(const P&, const char* field_name, const F& field) {
45 using base::trace_event::EstimateMemoryUsage; 45 using base::trace_event::EstimateMemoryUsage;
46 // All object fields are dynamically allocated. 46 // All object fields are dynamically allocated.
47 memory_usage_ += sizeof(F) + EstimateMemoryUsage(field); 47 memory_usage_ += sizeof(F) + EstimateMemoryUsage(field);
48 } 48 }
49 49
50 // Integral types 50 // Arithmetic types
51 template <class P, class F> 51 template <class P, class F>
52 typename std::enable_if<std::is_integral<F>::value>::type 52 typename std::enable_if<std::is_arithmetic<F>::value>::type
53 Visit(const P&, const char* field_name, const F& field) { 53 Visit(const P&, const char* field_name, const F& field) {
54 // Integral fields (integers, floats & bool) don't allocate. 54 // Arithmetic fields (integers, floats & bool) don't allocate.
55 } 55 }
56 56
57 // std::string 57 // std::string
58 template <class P> 58 template <class P>
59 void Visit(const P&, const char* field_name, const std::string& field) { 59 void Visit(const P&, const char* field_name, const std::string& field) {
60 using base::trace_event::EstimateMemoryUsage; 60 using base::trace_event::EstimateMemoryUsage;
61 // All strings are of type ArenaStringPtr, which essentially 61 // All strings are of type ArenaStringPtr, which essentially
62 // is std::string*. 62 // is std::string*.
63 memory_usage_ += sizeof(std::string) + EstimateMemoryUsage(field); 63 memory_usage_ += sizeof(std::string) + EstimateMemoryUsage(field);
64 } 64 }
65 65
66 // RepeatedPtrField 66 // RepeatedPtrField
67 template <class P, class F> 67 template <class P, class F>
68 void Visit(const P&, 68 void Visit(const P&,
69 const char* field_name, 69 const char* field_name,
70 const google::protobuf::RepeatedPtrField<F>& fields) { 70 const google::protobuf::RepeatedPtrField<F>& fields) {
71 using base::trace_event::EstimateMemoryUsage; 71 using base::trace_event::EstimateMemoryUsage;
72 // Can't use RepeatedPtrField::SpaceUsedExcludingSelf() because it will 72 // Can't use RepeatedPtrField::SpaceUsedExcludingSelf() because it will
73 // end up calling undefined TypeHandler::SpaceUsed() method. 73 // end up calling undefined TypeHandler::SpaceUsed() method.
74 memory_usage_ += fields.Capacity() ? sizeof(void*) : 0; // header 74 memory_usage_ += fields.Capacity() ? sizeof(void*) : 0; // header
75 memory_usage_ += fields.Capacity() * sizeof(void*); 75 memory_usage_ += fields.Capacity() * sizeof(void*);
76 for (const auto& field : fields) { 76 for (const auto& field : fields) {
77 memory_usage_ += sizeof(F) + EstimateMemoryUsage(field); 77 memory_usage_ += sizeof(F) + EstimateMemoryUsage(field);
78 } 78 }
79 } 79 }
80 80
81 // RepeatedField<integral type> 81 // RepeatedField<arithmetic type>
82 template <class P, class F> 82 template <class P, class F>
83 typename std::enable_if<std::is_integral<F>::value>::type Visit( 83 typename std::enable_if<std::is_arithmetic<F>::value>::type Visit(
84 const P&, 84 const P&,
85 const char* field_name, 85 const char* field_name,
86 const google::protobuf::RepeatedField<F>& fields) { 86 const google::protobuf::RepeatedField<F>& fields) {
87 memory_usage_ += fields.SpaceUsedExcludingSelf(); 87 memory_usage_ += fields.SpaceUsedExcludingSelf();
88 // Integral fields (integers, floats & bool) don't allocate, so no 88 // Arithmetic fields (integers, floats & bool) don't allocate, so no point
89 // point in iterating over |fields|. 89 // in iterating over |fields|.
90 } 90 }
91 91
92 // RepeatedField<std::string> 92 // RepeatedField<std::string>
93 template <class P> 93 template <class P>
94 void Visit(const P&, 94 void Visit(const P&,
95 const char* field_name, 95 const char* field_name,
96 const google::protobuf::RepeatedField<std::string>& fields) { 96 const google::protobuf::RepeatedField<std::string>& fields) {
97 using base::trace_event::EstimateMemoryUsage; 97 using base::trace_event::EstimateMemoryUsage;
98 memory_usage_ += fields.SpaceUsedExcludingSelf(); 98 memory_usage_ += fields.SpaceUsedExcludingSelf();
99 for (const auto& field : fields) { 99 for (const auto& field : fields) {
(...skipping 22 matching lines...) Expand all
122 template size_t EstimateMemoryUsage<Proto>(const Proto&); 122 template size_t EstimateMemoryUsage<Proto>(const Proto&);
123 123
124 INSTANTIATE(AttachmentMetadata) 124 INSTANTIATE(AttachmentMetadata)
125 INSTANTIATE(DataTypeContext) 125 INSTANTIATE(DataTypeContext)
126 INSTANTIATE(EntityMetadata) 126 INSTANTIATE(EntityMetadata)
127 INSTANTIATE(EntitySpecifics) 127 INSTANTIATE(EntitySpecifics)
128 INSTANTIATE(ModelTypeState) 128 INSTANTIATE(ModelTypeState)
129 INSTANTIATE(UniquePosition) 129 INSTANTIATE(UniquePosition)
130 130
131 } // namespace sync_pb 131 } // namespace sync_pb
OLDNEW
« no previous file with comments | « components/sync/protocol/proto_enum_conversions.cc ('k') | components/sync/protocol/proto_visitors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698