Internal change

PiperOrigin-RevId: 485219994
pull/10861/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 6e2102c8e3
commit 1c46a3374b
  1. 1
      src/google/protobuf/compiler/BUILD.bazel
  2. 17
      src/google/protobuf/compiler/command_line_interface.cc

@ -83,6 +83,7 @@ cc_library(
":code_generator",
":importer",
"//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],

@ -34,6 +34,7 @@
#include "google/protobuf/compiler/command_line_interface.h"
#include "absl/container/btree_map.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/platform_macros.h"
@ -427,7 +428,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
// The files_ field maps from path keys to file content values. It's a map
// instead of an unordered_map so that files are written in order (good when
// writing zips).
absl::flat_hash_map<std::string, std::string> files_;
absl::btree_map<std::string, std::string> files_;
const std::vector<const FileDescriptor*>& parsed_files_;
bool had_error_;
};
@ -805,7 +806,8 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
}
it->second.swap(data_);
} else {
return;
}
// This was an OpenForInsert().
// If the data doesn't end with a clean line break, add one.
@ -815,8 +817,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// Find the file we are going to insert into.
if (!already_present) {
std::cerr << filename_
<< ": Tried to insert into file that doesn't exist."
std::cerr << filename_ << ": Tried to insert into file that doesn't exist."
<< std::endl;
directory_->had_error_ = true;
return;
@ -862,7 +863,8 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// No indent. This makes things easier.
target->insert(pos, data_);
UpdateMetadata(data_, pos, data_.size(), 0);
} else {
return;
}
// Calculate how much space we need.
int indent_size = 0;
for (int i = 0; i < data_.size(); i++) {
@ -889,11 +891,10 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
target_ptr += line_length;
data_pos += line_length;
}
UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size());
GOOGLE_CHECK_EQ(target_ptr, &(*target)[pos] + data_.size() + indent_size);
}
}
UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size());
}
// ===================================================================

Loading…
Cancel
Save