Incremental migration of message.cc to Emit

PiperOrigin-RevId: 529830599
pull/12689/head
Matt Kulukundis 2 years ago committed by Copybara-Service
parent 117b0ffc8b
commit 8a443699f7
  1. 79
      src/google/protobuf/compiler/cpp/message.cc

@ -45,10 +45,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/generated_message_util.h"
#include "google/protobuf/map_entry_lite.h"
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "absl/log/absl_check.h" #include "absl/log/absl_check.h"
@ -59,7 +55,6 @@
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/cpp/enum.h" #include "google/protobuf/compiler/cpp/enum.h"
#include "google/protobuf/compiler/cpp/extension.h" #include "google/protobuf/compiler/cpp/extension.h"
#include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/field.h"
@ -430,7 +425,6 @@ bool ColdChunkSkipper::IsColdChunk(int chunk) {
void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index,
const std::string& from, io::Printer* p) { const std::string& from, io::Printer* p) {
Formatter format(p);
if (!access_info_map_) { if (!access_info_map_) {
return; return;
} else if (chunk < limit_chunk_) { } else if (chunk < limit_chunk_) {
@ -454,42 +448,53 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index,
} }
// Emit has_bit check for each has_bit_dword index. // Emit has_bit check for each has_bit_dword index.
format("if (PROTOBUF_PREDICT_FALSE("); p->Emit(
int first_word = HasbitWord(chunk, 0); {{"cond",
while (chunk < limit_chunk_) { [&] {
uint32_t mask = 0; int first_word = HasbitWord(chunk, 0);
int this_word = HasbitWord(chunk, 0); while (chunk < limit_chunk_) {
// Generate mask for chunks on the same word. uint32_t mask = 0;
for (; chunk < limit_chunk_ && HasbitWord(chunk, 0) == this_word; chunk++) { int this_word = HasbitWord(chunk, 0);
for (auto field : chunks_[chunk]) { // Generate mask for chunks on the same word.
int hasbit_index = has_bit_indices_[field->index()]; for (; chunk < limit_chunk_ && HasbitWord(chunk, 0) == this_word;
// Fields on a chunk must be in the same word. chunk++) {
ABSL_CHECK_EQ(this_word, hasbit_index / 32); for (auto field : chunks_[chunk]) {
mask |= 1 << (hasbit_index % 32); int hasbit_index = has_bit_indices_[field->index()];
} // Fields on a chunk must be in the same word.
} ABSL_CHECK_EQ(this_word, hasbit_index / 32);
mask |= 1 << (hasbit_index % 32);
}
}
if (this_word != first_word) { Formatter format(p);
format(" ||\n "); if (this_word != first_word) {
} p->Emit(R"cc(
auto v = p->WithVars({{"mask", absl::Hex(mask, absl::kZeroPad8)}}); ||
if (this_word == cached_has_word_index) { )cc");
format("(cached_has_bits & 0x$mask$u) != 0"); }
} else { auto v = p->WithVars({{"mask", absl::StrFormat("0x%08xu", mask)}});
format("($1$_impl_._has_bits_[$2$] & 0x$mask$u) != 0", from, this_word); if (this_word == cached_has_word_index) {
} p->Emit("(cached_has_bits & $mask$) != 0");
} } else {
format(")) {\n"); p->Emit({{"from", from}, {"word", this_word}},
format.Indent(); "($from$_impl_._has_bits_[$word$] & $mask$) != 0");
}
}
}}},
R"cc(
if (PROTOBUF_PREDICT_FALSE($cond$)) {
)cc");
p->Indent();
} }
bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* p) { bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* p) {
Formatter format(p);
if (chunk != limit_chunk_ - 1) { if (chunk != limit_chunk_ - 1) {
return false; return false;
} }
format.Outdent(); p->Outdent();
format("}\n"); p->Emit(R"cc(
}
)cc");
return true; return true;
} }
@ -2395,9 +2400,7 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* p) {
} }
format.Outdent(); format.Outdent();
format( format("}\n\n");
"}\n"
"\n");
} }
ArenaDtorNeeds MessageGenerator::NeedsArenaDestructor() const { ArenaDtorNeeds MessageGenerator::NeedsArenaDestructor() const {

Loading…
Cancel
Save