Migrate std::unordered_map -> absl::flat_hash_map.

pull/13171/head
Joshua Haberman 6 years ago
parent 06b90f9b69
commit ef9499cb44
  1. 1
      BUILD
  2. 5
      upbc/generator.cc
  3. 10
      upbc/message_layout.h

@ -207,6 +207,7 @@ cc_library(
copts = CPPOPTS,
deps = [
"@absl//absl/base:core_headers",
"@absl//absl/container:flat_hash_map",
"@absl//absl/strings",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:protoc_lib",

@ -1,8 +1,7 @@
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/substitute.h"
@ -594,7 +593,7 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output) {
std::string fields_array_ref = "NULL";
std::string submsgs_array_ref = "NULL";
std::string oneofs_array_ref = "NULL";
std::unordered_map<const protobuf::Descriptor*, int> submsg_indexes;
absl::flat_hash_map<const protobuf::Descriptor*, int> submsg_indexes;
MessageLayout layout(message);
std::vector<const protobuf::FieldDescriptor*> sorted_submsgs =
SortedSubmessages(message);

@ -2,8 +2,8 @@
#ifndef UPBC_MESSAGE_LAYOUT_H
#define UPBC_MESSAGE_LAYOUT_H
#include <unordered_map>
#include "absl/base/macros.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/descriptor.h"
namespace upbc {
@ -70,7 +70,7 @@ class MessageLayout {
Size Place(SizeAndAlign size_and_align);
template <class K, class V>
static V GetMapValue(const std::unordered_map<K, V>& map, K key) {
static V GetMapValue(const absl::flat_hash_map<K, V>& map, K key) {
auto iter = map.find(key);
if (iter == map.end()) {
fprintf(stderr, "No value for field.\n");
@ -92,11 +92,11 @@ class MessageLayout {
static int64_t FieldLayoutRank(
const google::protobuf::FieldDescriptor* field);
std::unordered_map<const google::protobuf::FieldDescriptor*, Size>
absl::flat_hash_map<const google::protobuf::FieldDescriptor*, Size>
field_offsets_;
std::unordered_map<const google::protobuf::FieldDescriptor*, int>
absl::flat_hash_map<const google::protobuf::FieldDescriptor*, int>
hasbit_indexes_;
std::unordered_map<const google::protobuf::OneofDescriptor*, Size>
absl::flat_hash_map<const google::protobuf::OneofDescriptor*, Size>
oneof_case_offsets_;
Size maxalign_;
Size size_;

Loading…
Cancel
Save