aboutsummaryrefslogtreecommitdiffhomepage
path: root/benchmarks
diff options
context:
space:
mode:
authorGravatar Yilun Chong <yilunchong@google.com>2018-06-04 10:16:40 -0700
committerGravatar Yilun Chong <yilunchong@google.com>2018-06-04 10:16:40 -0700
commit61dac6d592fa3e384f77d914b67eb22c5d26104a (patch)
tree1e53638dc50ac8945437995ac637c66efef30b78 /benchmarks
parent193af9f4c1ebfeec4c9322fc4bbb2a513267d345 (diff)
Fix
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/util/data_proto2_to_proto3_util.h1
-rw-r--r--benchmarks/util/protoc-gen-proto2_to_proto3.cc61
-rw-r--r--benchmarks/util/schema_proto2_to_proto3_util.h3
3 files changed, 36 insertions, 29 deletions
diff --git a/benchmarks/util/data_proto2_to_proto3_util.h b/benchmarks/util/data_proto2_to_proto3_util.h
index 7207efde..5eea8509 100644
--- a/benchmarks/util/data_proto2_to_proto3_util.h
+++ b/benchmarks/util/data_proto2_to_proto3_util.h
@@ -23,6 +23,7 @@ class DataStripper {
const FieldDescriptor* field = set_fields[i];
if (ShouldBeClear(field)) {
reflection->ClearField(message, field);
+ continue;
}
if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
if (field->is_repeated()) {
diff --git a/benchmarks/util/protoc-gen-proto2_to_proto3.cc b/benchmarks/util/protoc-gen-proto2_to_proto3.cc
index b1e6ba41..d0a89023 100644
--- a/benchmarks/util/protoc-gen-proto2_to_proto3.cc
+++ b/benchmarks/util/protoc-gen-proto2_to_proto3.cc
@@ -23,42 +23,25 @@ namespace compiler {
namespace {
string StripProto(string filename) {
- if (filename.substr(filename.size() - 11) == ".protodevel") {
- // .protodevel
- return filename.substr(0, filename.size() - 11);
- } else {
- // .proto
- return filename.substr(0, filename.size() - 6);
- }
+ return filename.substr(0, filename.rfind(".proto"));
}
-DescriptorPool new_pool_;
+DescriptorPool* GetPool() {
+ static DescriptorPool *pool = new DescriptorPool();
+ return pool;
+}
} // namespace
-class Proto2ToProto3Generator : public CodeGenerator {
+class Proto2ToProto3Generator final : public CodeGenerator {
public:
- virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files,
+ bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const string& parameter,
GeneratorContext* context,
string* error) const {
for (int i = 0; i < files.size(); i++) {
for (auto file : files) {
- bool can_generate =
- (new_pool_.FindFileByName(file->name()) == nullptr);
- for (int j = 0; j < file->dependency_count(); j++) {
- can_generate &= (new_pool_.FindFileByName(
- file->dependency(j)->name()) != nullptr);
- }
- for (int j = 0; j < file->public_dependency_count(); j++) {
- can_generate &= (new_pool_.FindFileByName(
- file->public_dependency(j)->name()) != nullptr);
- }
- for (int j = 0; j < file->weak_dependency_count(); j++) {
- can_generate &= (new_pool_.FindFileByName(
- file->weak_dependency(j)->name()) != nullptr);
- }
- if (can_generate) {
+ if (CanGenerate(file)) {
Generate(file, parameter, context, error);
break;
}
@@ -68,7 +51,7 @@ class Proto2ToProto3Generator : public CodeGenerator {
return true;
}
- virtual bool Generate(const FileDescriptor* file,
+ bool Generate(const FileDescriptor* file,
const string& parameter,
GeneratorContext* context,
string* error) const {
@@ -90,12 +73,36 @@ class Proto2ToProto3Generator : public CodeGenerator {
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->Open(basename + ".proto"));
- string content = new_pool_.BuildFile(new_file)->DebugString();
+ string content = GetPool()->BuildFile(new_file)->DebugString();
Printer printer(output.get(), '$');
printer.WriteRaw(content.c_str(), content.size());
return true;
}
+ private:
+ bool CanGenerate(const FileDescriptor* file) const {
+ if (GetPool()->FindFileByName(file->name()) != nullptr) {
+ return false;
+ }
+ for (int j = 0; j < file->dependency_count(); j++) {
+ if (GetPool()->FindFileByName(file->dependency(j)->name()) == nullptr) {
+ return false;
+ }
+ }
+ for (int j = 0; j < file->public_dependency_count(); j++) {
+ if (GetPool()->FindFileByName(
+ file->public_dependency(j)->name()) == nullptr) {
+ return false;
+ }
+ }
+ for (int j = 0; j < file->weak_dependency_count(); j++) {
+ if (GetPool()->FindFileByName(
+ file->weak_dependency(j)->name()) == nullptr) {
+ return false;
+ }
+ }
+ return true;
+ }
};
} // namespace compiler
diff --git a/benchmarks/util/schema_proto2_to_proto3_util.h b/benchmarks/util/schema_proto2_to_proto3_util.h
index 8cbcbc40..0079f6f1 100644
--- a/benchmarks/util/schema_proto2_to_proto3_util.h
+++ b/benchmarks/util/schema_proto2_to_proto3_util.h
@@ -164,8 +164,7 @@ class FieldScrubber {
}
private:
static bool ShouldClearLabel(const FieldDescriptorProto *field) {
- return field->label() == FieldDescriptorProto::LABEL_OPTIONAL ||
- field->label() == FieldDescriptorProto::LABEL_REQUIRED;
+ return field->label() == FieldDescriptorProto::LABEL_REQUIRED;
}
static void ScrubMessage(DescriptorProto *message_type) {