34
34
#include " Firestore/core/src/nanopb/message.h"
35
35
#include " Firestore/core/src/nanopb/nanopb_util.h"
36
36
#include " Firestore/core/src/timestamp_internal.h"
37
+ #include " Firestore/core/src/util/no_destructor.h"
37
38
#include " Firestore/core/src/util/statusor.h"
38
39
#include " Firestore/core/src/util/string_format.h"
39
40
#include " Firestore/core/src/util/string_util.h"
@@ -72,18 +73,19 @@ using nanopb::Message;
72
73
using nanopb::SetRepeatedField;
73
74
using nanopb::SharedMessage;
74
75
using nlohmann::json;
76
+ using util::NoDestructor;
75
77
using util::StatusOr;
76
78
using util::StringFormat;
77
79
using Operator = FieldFilter::Operator;
78
80
79
81
namespace {
80
- const Bound kDefaultBound = Bound::FromValue(
81
- MakeSharedMessage<google_firestore_v1_ArrayValue>({}), false );
82
+ const NoDestructor< Bound> kDefaultBound { Bound::FromValue (
83
+ MakeSharedMessage<google_firestore_v1_ArrayValue>({}), false )} ;
82
84
} // namespace
83
85
84
86
template <typename T>
85
87
const std::vector<T>& EmptyVector () {
86
- static auto * empty = new std::vector<T>;
88
+ static NoDestructor< std::vector<T>> empty ;
87
89
return *empty;
88
90
}
89
91
@@ -658,7 +660,7 @@ FilterList BundleSerializer::DecodeCompositeFilter(JsonReader& reader,
658
660
Bound BundleSerializer::DecodeStartAtBound (JsonReader& reader,
659
661
const json& query) const {
660
662
if (!query.contains (" startAt" )) {
661
- return kDefaultBound ;
663
+ return * kDefaultBound ;
662
664
}
663
665
664
666
auto result =
@@ -669,7 +671,7 @@ Bound BundleSerializer::DecodeStartAtBound(JsonReader& reader,
669
671
Bound BundleSerializer::DecodeEndAtBound (JsonReader& reader,
670
672
const json& query) const {
671
673
if (!query.contains (" endAt" )) {
672
- return kDefaultBound ;
674
+ return * kDefaultBound ;
673
675
}
674
676
675
677
auto result =
0 commit comments