|
|
|
@ -11,6 +11,7 @@ |
|
|
|
|
|
|
|
|
|
#include "google/protobuf/message.h" |
|
|
|
|
|
|
|
|
|
#include <atomic> |
|
|
|
|
#include <cstddef> |
|
|
|
|
#include <cstdint> |
|
|
|
|
#include <cstring> |
|
|
|
@ -257,7 +258,7 @@ class GeneratedMessageFactory final : public MessageFactory { |
|
|
|
|
{ |
|
|
|
|
auto it = type_map_.find(type); |
|
|
|
|
if (it == type_map_.end()) return absl::nullopt; |
|
|
|
|
return it->second; |
|
|
|
|
return it->second.get(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const google::protobuf::internal::DescriptorTable* FindInFileMap( |
|
|
|
@ -303,7 +304,17 @@ class GeneratedMessageFactory final : public MessageFactory { |
|
|
|
|
DynamicMessageFactory dropped_defaults_factory_; |
|
|
|
|
|
|
|
|
|
absl::Mutex mutex_; |
|
|
|
|
absl::flat_hash_map<const Descriptor*, const Message*> type_map_ |
|
|
|
|
class MessagePtr { |
|
|
|
|
public: |
|
|
|
|
MessagePtr() : value_() {} |
|
|
|
|
explicit MessagePtr(const Message* msg) : value_(msg) {} |
|
|
|
|
const Message* get() const { return value_; } |
|
|
|
|
void set(const Message* msg) { value_ = msg; } |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
const Message* value_; |
|
|
|
|
}; |
|
|
|
|
absl::flat_hash_map<const Descriptor*, MessagePtr> type_map_ |
|
|
|
|
ABSL_GUARDED_BY(mutex_); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -352,7 +363,7 @@ const Message* GeneratedMessageFactory::GetPrototype(const Descriptor* type) { |
|
|
|
|
// And update the main map to make the next lookup faster.
|
|
|
|
|
// We don't need to recheck here. Even if someone raced us here the result
|
|
|
|
|
// is the same, so we can just write it.
|
|
|
|
|
type_map_[type] = result; |
|
|
|
|
type_map_[type].set(result); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|