Move some processing off to a secondary noinline function. This significantly

reduces the stack usage of the recursive function.

PiperOrigin-RevId: 567286733
pull/14147/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 1180543de9
commit e71ce645d2
  1. 43
      src/google/protobuf/compiler/parser.cc

@ -799,25 +799,8 @@ bool Parser::ParseTopLevelStatement(FileDescriptorProto* file,
// -------------------------------------------------------------------
// Messages
bool Parser::ParseMessageDefinition(
DescriptorProto* message, const LocationRecorder& message_location,
const FileDescriptorProto* containing_file) {
DO(Consume("message"));
{
LocationRecorder location(message_location,
DescriptorProto::kNameFieldNumber);
location.RecordLegacyLocation(message,
DescriptorPool::ErrorCollector::NAME);
DO(ConsumeIdentifier(message->mutable_name(), "Expected message name."));
if (!IsUpperCamelCase(message->name())) {
RecordWarning(absl::StrCat(
"Message name should be in UpperCamelCase. Found: ", message->name(),
". See https://developers.google.com/protocol-buffers/docs/style"));
}
}
DO(ParseMessageBlock(message, message_location, containing_file));
if (syntax_identifier_ == "proto3") {
PROTOBUF_NOINLINE static void GenerateSyntheticOneofs(
DescriptorProto* message) {
// Add synthetic one-field oneofs for optional fields, except messages which
// already have presence in proto3.
//
@ -853,6 +836,28 @@ bool Parser::ParseMessageDefinition(
}
}
bool Parser::ParseMessageDefinition(
DescriptorProto* message, const LocationRecorder& message_location,
const FileDescriptorProto* containing_file) {
DO(Consume("message"));
{
LocationRecorder location(message_location,
DescriptorProto::kNameFieldNumber);
location.RecordLegacyLocation(message,
DescriptorPool::ErrorCollector::NAME);
DO(ConsumeIdentifier(message->mutable_name(), "Expected message name."));
if (!IsUpperCamelCase(message->name())) {
RecordWarning(absl::StrCat(
"Message name should be in UpperCamelCase. Found: ", message->name(),
". See https://developers.google.com/protocol-buffers/docs/style"));
}
}
DO(ParseMessageBlock(message, message_location, containing_file));
if (syntax_identifier_ == "proto3") {
GenerateSyntheticOneofs(message);
}
return true;
}

Loading…
Cancel
Save