@@ -2530,22 +2530,18 @@ class PROTOBUF_EXPORT DescriptorPool {
2530
2530
auto key = std::pair<const void *, const void *>(field, &type_key);
2531
2531
{
2532
2532
absl::ReaderMutexLock lock (&field_memo_table_mutex_);
2533
- auto it = field_memo_table_. find (key);
2534
- if (it != field_memo_table_. end ()) {
2533
+ auto it = field_memo_table_-> find (key);
2534
+ if (it != field_memo_table_-> end ()) {
2535
2535
return internal::DownCast<const MemoData<ResultT>&>(*it->second ).value ;
2536
2536
}
2537
2537
}
2538
2538
auto result = std::make_unique<MemoData<ResultT>>();
2539
2539
result->value = func (field);
2540
2540
{
2541
2541
absl::MutexLock lock (&field_memo_table_mutex_);
2542
- auto & res = field_memo_table_[key];
2543
- // Only initialize the first time. We don't want to invalidate old
2544
- // references.
2545
- if (res == nullptr ) {
2546
- res = std::move (result);
2547
- }
2548
- return internal::DownCast<const MemoData<ResultT>&>(*res).value ;
2542
+ auto insert_result = field_memo_table_->insert ({key, std::move (result)});
2543
+ auto it = insert_result.first ;
2544
+ return internal::DownCast<const MemoData<ResultT>&>(*it->second ).value ;
2549
2545
}
2550
2546
}
2551
2547
// Return true if the given name is a sub-symbol of any non-package
@@ -2608,9 +2604,12 @@ class PROTOBUF_EXPORT DescriptorPool {
2608
2604
2609
2605
#ifndef SWIG
2610
2606
mutable absl::Mutex field_memo_table_mutex_;
2611
- mutable absl::flat_hash_map<std::pair<const void *, const void *>,
2612
- std::unique_ptr<MemoBase>>
2613
- field_memo_table_ ABSL_GUARDED_BY (field_memo_table_mutex_);
2607
+ mutable std::unique_ptr<absl::flat_hash_map<
2608
+ std::pair<const void *, const void *>, std::unique_ptr<MemoBase>>>
2609
+ field_memo_table_ ABSL_GUARDED_BY (field_memo_table_mutex_) =
2610
+ std::make_unique<
2611
+ absl::flat_hash_map<std::pair<const void*, const void*>,
2612
+ std::unique_ptr<MemoBase>>>();
2614
2613
#endif // SWIG
2615
2614
2616
2615
// If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a
0 commit comments