54 void Append(
const FieldGroup& other) {
55 if (other.fields_.empty()) {
61 (other.preferred_location_ * other.fields_.size())) /
62 (
fields_.size() + other.fields_.size());
63 fields_.insert(
fields_.end(), other.fields_.begin(), other.fields_.end());
67 const std::vector<const FieldDescriptor*>&
fields()
const {
return fields_; }
70 bool operator<(
const FieldGroup& other)
const {
81 std::vector<const FieldDescriptor*>
fields_;
131 ZERO_INITIALIZABLE = 4,
137 std::vector<FieldGroup> aligned_to_1[kMaxFamily];
138 std::vector<FieldGroup> aligned_to_4[kMaxFamily];
139 std::vector<FieldGroup> aligned_to_8[kMaxFamily];
140 for (
int i = 0;
i <
fields->size(); ++
i) {
144 if (
field->is_repeated()) {
154 f = ZERO_INITIALIZABLE;
157 const int j =
field->number();
160 aligned_to_1[
f].push_back(FieldGroup(j,
field));
163 aligned_to_4[
f].push_back(FieldGroup(j,
field));
166 aligned_to_8[
f].push_back(FieldGroup(j,
field));
170 <<
"for a field " <<
field->full_name() <<
".";
175 for (
int f = 0;
f < kMaxFamily;
f++) {
178 for (
int i = 0;
i < aligned_to_1[
f].size();
i += 4) {
179 FieldGroup field_group;
180 for (
int j =
i; j < aligned_to_1[
f].size() && j <
i + 4; ++j) {
181 field_group.Append(aligned_to_1[
f][j]);
183 aligned_to_4[
f].push_back(field_group);
188 std::stable_sort(aligned_to_4[
f].
begin(), aligned_to_4[
f].
end());
192 for (
int i = 0;
i < aligned_to_4[
f].size();
i += 2) {
193 FieldGroup field_group;
194 for (
int j =
i; j < aligned_to_4[
f].size() && j <
i + 2; ++j) {
195 field_group.Append(aligned_to_4[
f][j]);
197 if (
i == aligned_to_4[
f].
size() - 1) {
202 field_group.SetPreferredLocation(-1);
205 field_group.SetPreferredLocation(
fields->size() + 1);
208 aligned_to_8[
f].push_back(field_group);
211 std::stable_sort(aligned_to_8[
f].
begin(), aligned_to_8[
f].
end());
216 for (
int f = 0;
f < kMaxFamily; ++
f) {
217 for (
int i = 0;
i < aligned_to_8[
f].size(); ++
i) {
218 fields->insert(
fields->end(), aligned_to_8[
f][
i].fields().begin(),
219 aligned_to_8[
f][
i].fields().end());