• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 // Author: seongkim@google.com (Seong Beom Kim)
9 //  Based on original Protocol Buffers design by
10 //  Sanjay Ghemawat, Jeff Dean, and others.
11 
12 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__
13 #define GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__
14 
15 #include "google/protobuf/compiler/cpp/message_layout_helper.h"
16 
17 namespace google {
18 namespace protobuf {
19 namespace compiler {
20 namespace cpp {
21 
22 // Rearranges the fields of a message to minimize padding.
23 // Fields are grouped by the type and the size.
24 // For example, grouping four boolean fields and one int32
25 // field results in zero padding overhead. See OptimizeLayout's
26 // comment for details.
27 class PaddingOptimizer : public MessageLayoutHelper {
28  public:
PaddingOptimizer()29   PaddingOptimizer() {}
~PaddingOptimizer()30   ~PaddingOptimizer() override {}
31 
32   void OptimizeLayout(std::vector<const FieldDescriptor*>* fields,
33                       const Options& options,
34                       MessageSCCAnalyzer* scc_analyzer) override;
35 };
36 
37 }  // namespace cpp
38 }  // namespace compiler
39 }  // namespace protobuf
40 }  // namespace google
41 
42 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__
43