diff --git a/Firestore/core/src/api/collection_reference.cc b/Firestore/core/src/api/collection_reference.cc index a6d8f731965..46619cf1799 100644 --- a/Firestore/core/src/api/collection_reference.cc +++ b/Firestore/core/src/api/collection_reference.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/api/collection_reference.h" +#include #include #include "Firestore/core/src/api/document_reference.h" @@ -67,10 +68,10 @@ const std::string& CollectionReference::collection_id() const { return query().path().last_segment(); } -absl::optional CollectionReference::parent() const { +std::optional CollectionReference::parent() const { ResourcePath parent_path = query().path().PopLast(); if (parent_path.empty()) { - return absl::nullopt; + return std::nullopt; } else { return DocumentReference(DocumentKey(std::move(parent_path)), firestore()); } diff --git a/Firestore/core/src/api/document_snapshot.cc b/Firestore/core/src/api/document_snapshot.cc index ee1eb681c66..49a2dd04a3c 100644 --- a/Firestore/core/src/api/document_snapshot.cc +++ b/Firestore/core/src/api/document_snapshot.cc @@ -16,12 +16,12 @@ #include "Firestore/core/src/api/document_snapshot.h" +#include #include #include "Firestore/core/src/api/document_reference.h" #include "Firestore/core/src/model/resource_path.h" #include "Firestore/core/src/util/hashing.h" -#include "absl/types/optional.h" namespace firebase { namespace firestore { @@ -44,13 +44,13 @@ DocumentSnapshot DocumentSnapshot::FromNoDocument( std::shared_ptr firestore, model::DocumentKey key, SnapshotMetadata metadata) { - return DocumentSnapshot{std::move(firestore), std::move(key), absl::nullopt, + return DocumentSnapshot{std::move(firestore), std::move(key), std::nullopt, std::move(metadata)}; } DocumentSnapshot::DocumentSnapshot(std::shared_ptr firestore, model::DocumentKey document_key, - absl::optional document, + std::optional document, SnapshotMetadata metadata) : firestore_{std::move(firestore)}, internal_key_{std::move(document_key)}, @@ -67,7 +67,7 @@ bool DocumentSnapshot::exists() const { return internal_document_.has_value(); } -const absl::optional& DocumentSnapshot::internal_document() const { +const std::optional& DocumentSnapshot::internal_document() const { return internal_document_; } @@ -79,10 +79,10 @@ const std::string& DocumentSnapshot::document_id() const { return internal_key_.path().last_segment(); } -absl::optional DocumentSnapshot::GetValue( +std::optional DocumentSnapshot::GetValue( const FieldPath& field_path) const { return internal_document_ ? (*internal_document_)->field(field_path) - : absl::nullopt; + : std::nullopt; } bool operator==(const DocumentSnapshot& lhs, const DocumentSnapshot& rhs) { diff --git a/Firestore/core/src/api/load_bundle_task.cc b/Firestore/core/src/api/load_bundle_task.cc index e0da2ae6e94..c98fd9472ed 100644 --- a/Firestore/core/src/api/load_bundle_task.cc +++ b/Firestore/core/src/api/load_bundle_task.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/api/load_bundle_task.h" #include +#include #include #include "Firestore/core/src/util/autoid.h" @@ -66,7 +67,7 @@ void LoadBundleTask::RemoveObserver(const LoadBundleHandle& handle) { } if (last_observer_.has_value() && last_observer_.value().first == handle) { - last_observer_ = absl::nullopt; + last_observer_ = std::nullopt; } } @@ -74,7 +75,7 @@ void LoadBundleTask::RemoveAllObservers() { std::lock_guard lock(mutex_); observers_.clear(); - last_observer_ = absl::nullopt; + last_observer_ = std::nullopt; } void LoadBundleTask::SetSuccess(LoadBundleTaskProgress success_progress) { diff --git a/Firestore/core/src/bundle/bundle_loader.cc b/Firestore/core/src/bundle/bundle_loader.cc index 5f56ddcf2cd..1707409e60b 100644 --- a/Firestore/core/src/bundle/bundle_loader.cc +++ b/Firestore/core/src/bundle/bundle_loader.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/bundle/bundle_loader.h" #include +#include #include #include "Firestore/core/include/firebase/firestore/firestore_errors.h" @@ -62,7 +63,7 @@ Status BundleLoader::AddElementInternal(const BundleElement& element) { document_metadata.key(), MutableDocument::NoDocument(document_metadata.key(), document_metadata.read_time())); - current_document_ = absl::nullopt; + current_document_ = std::nullopt; } break; } @@ -77,7 +78,7 @@ Status BundleLoader::AddElementInternal(const BundleElement& element) { } documents_ = documents_.insert(document.key(), document.document()); - current_document_ = absl::nullopt; + current_document_ = std::nullopt; break; } @@ -90,7 +91,7 @@ Status BundleLoader::AddElementInternal(const BundleElement& element) { return Status::OK(); } -StatusOr> BundleLoader::AddElement( +StatusOr> BundleLoader::AddElement( std::unique_ptr element_ptr, uint64_t byte_size) { HARD_ASSERT(element_ptr->element_type() != BundleElement::Type::Metadata, "Unexpected bundle metadata element."); @@ -106,17 +107,17 @@ StatusOr> BundleLoader::AddElement( // Document has only been partially loaded, no progress to report. if (before_count == documents_.size()) { - return {absl::nullopt}; + return {std::nullopt}; } LoadBundleTaskProgress progress{ documents_.size(), metadata_.total_documents(), bytes_loaded_, metadata_.total_bytes(), LoadBundleTaskState::kInProgress}; - return {absl::make_optional(std::move(progress))}; + return {std::make_optional(std::move(progress))}; } StatusOr BundleLoader::ApplyChanges() { - if (current_document_ != absl::nullopt) { + if (current_document_ != std::nullopt) { return StatusOr( Status(Error::kErrorInvalidArgument, "Bundled documents end with a document metadata " diff --git a/Firestore/core/src/bundle/bundle_reader.cc b/Firestore/core/src/bundle/bundle_reader.cc index 2f087aa5e36..df0e76f8200 100644 --- a/Firestore/core/src/bundle/bundle_reader.cc +++ b/Firestore/core/src/bundle/bundle_reader.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/bundle/bundle_reader.h" #include +#include #include "absl/memory/memory.h" #include "absl/strings/numbers.h" @@ -96,22 +97,22 @@ std::unique_ptr BundleReader::ReadNextElement() { return result; } -absl::optional BundleReader::ReadLengthPrefix() { +std::optional BundleReader::ReadLengthPrefix() { // length string of size 16 indicates an element about 1PB, which is // impossible for valid bundles. StreamReadResult result = input_->ReadUntil('{', 16); if (!result.ok()) { reader_status_.Update(result.status()); - return absl::nullopt; + return std::nullopt; } // Underlying stream is closed, and there happens to be no more data to // process. if (result.eof() && result.ValueOrDie().empty()) { - return absl::nullopt; + return std::nullopt; } - return absl::make_optional(std::move(result).ValueOrDie()); + return std::make_optional(std::move(result).ValueOrDie()); } void BundleReader::ReadJsonToBuffer(size_t required_size) { diff --git a/Firestore/core/src/core/query.cc b/Firestore/core/src/core/query.cc index ade33d8b940..3598ade2896 100644 --- a/Firestore/core/src/core/query.cc +++ b/Firestore/core/src/core/query.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include "Firestore/core/src/core/bound.h" @@ -80,7 +81,7 @@ const std::set Query::InequalityFilterFields() const { return result; } -absl::optional Query::FindOpInsideFilters( +std::optional Query::FindOpInsideFilters( const std::vector& ops) const { for (const auto& filter : filters_) { for (const auto& field_filter : filter.GetFlattenedFilters()) { @@ -89,7 +90,7 @@ absl::optional Query::FindOpInsideFilters( } } } - return absl::nullopt; + return std::nullopt; } std::shared_ptr> Query::CalculateNormalizedOrderBys() @@ -236,7 +237,7 @@ bool Query::MatchesOrderBy(const Document& doc) const { const FieldPath& field_path = order_by.field(); // order by key always matches if (field_path != FieldPath::KeyFieldPath() && - doc->field(field_path) == absl::nullopt) { + doc->field(field_path) == std::nullopt) { return false; } } @@ -316,13 +317,13 @@ Target Query::ToTarget(const std::vector& order_bys) const { // We need to swap the cursors to match the now-flipped query ordering. auto new_start_at = end_at_ - ? absl::optional{Bound::FromValue( + ? std::optional{Bound::FromValue( end_at_->position(), end_at_->inclusive())} - : absl::nullopt; + : std::nullopt; auto new_end_at = start_at_ - ? absl::optional{Bound::FromValue( + ? std::optional{Bound::FromValue( start_at_->position(), start_at_->inclusive())} - : absl::nullopt; + : std::nullopt; return Target(path(), collection_group(), filters(), new_order_bys, limit_, new_start_at, new_end_at); diff --git a/Firestore/core/src/core/sync_engine.cc b/Firestore/core/src/core/sync_engine.cc index defa08ead0b..9be41f97b53 100644 --- a/Firestore/core/src/core/sync_engine.cc +++ b/Firestore/core/src/core/sync_engine.cc @@ -16,6 +16,8 @@ #include "Firestore/core/src/core/sync_engine.h" +#include + #include "Firestore/core/include/firebase/firestore/firestore_errors.h" #include "Firestore/core/src/bundle/bundle_element.h" #include "Firestore/core/src/bundle/bundle_loader.h" @@ -140,7 +142,7 @@ ViewSnapshot SyncEngine::InitializeViewAndComputeSnapshot( // If there are already queries mapped to the target id, create a synthesized // target change to apply the sync state from those queries to the new query. auto current_sync_state = SyncState::None; - absl::optional synthesized_current_change; + std::optional synthesized_current_change; if (queries_by_target_.find(target_id) != queries_by_target_.end()) { const QueryOrPipeline& mirror_query = queries_by_target_[target_id][0]; current_sync_state = @@ -248,7 +250,7 @@ void SyncEngine::WriteMutations(std::vector&& mutations, mutation_callbacks_[current_user_].insert( std::make_pair(result.batch_id(), std::move(callback))); - EmitNewSnapshotsAndNotifyLocalStore(result.changes(), absl::nullopt); + EmitNewSnapshotsAndNotifyLocalStore(result.changes(), std::nullopt); remote_store_->FillWritePipeline(); } @@ -307,7 +309,7 @@ void SyncEngine::HandleCredentialChange(const credentials::User& user) { // Notify local store and emit any resulting events from swapping out the // mutation queue. DocumentMap changes = local_store_->HandleUserChange(user); - EmitNewSnapshotsAndNotifyLocalStore(changes, absl::nullopt); + EmitNewSnapshotsAndNotifyLocalStore(changes, std::nullopt); } // Notify remote store so it can restart its streams. @@ -407,7 +409,7 @@ void SyncEngine::HandleSuccessfulWrite( TriggerPendingWriteCallbacks(batch_result.batch().batch_id()); DocumentMap changes = local_store_->AcknowledgeBatch(batch_result); - EmitNewSnapshotsAndNotifyLocalStore(changes, absl::nullopt); + EmitNewSnapshotsAndNotifyLocalStore(changes, std::nullopt); } void SyncEngine::HandleRejectedWrite( @@ -430,7 +432,7 @@ void SyncEngine::HandleRejectedWrite( TriggerPendingWriteCallbacks(batch_id); - EmitNewSnapshotsAndNotifyLocalStore(changes, absl::nullopt); + EmitNewSnapshotsAndNotifyLocalStore(changes, std::nullopt); } void SyncEngine::HandleOnlineStateChange(model::OnlineState online_state) { @@ -512,7 +514,7 @@ void SyncEngine::FailOutstandingPendingWriteCallbacks( void SyncEngine::EmitNewSnapshotsAndNotifyLocalStore( const DocumentMap& changes, - const absl::optional& maybe_remote_event) { + const std::optional& maybe_remote_event) { std::vector new_snapshots; std::vector document_changes_in_all_views; @@ -530,7 +532,7 @@ void SyncEngine::EmitNewSnapshotsAndNotifyLocalStore( view_doc_changes); } - absl::optional target_changes; + std::optional target_changes; bool targetIsPendingReset = false; if (maybe_remote_event.has_value()) { const RemoteEvent& remote_event = maybe_remote_event.value(); @@ -631,7 +633,7 @@ void SyncEngine::RemoveLimboTarget(const DocumentKey& key) { PumpEnqueuedLimboResolutions(); } -absl::optional SyncEngine::ReadIntoLoader( +std::optional SyncEngine::ReadIntoLoader( const bundle::BundleMetadata& metadata, bundle::BundleReader& reader, api::LoadBundleTask& result_task) { @@ -645,7 +647,7 @@ absl::optional SyncEngine::ReadIntoLoader( LOG_WARN("Failed to GetNextElement() from bundle with error %s", reader.reader_status().error_message()); result_task.SetError(reader.reader_status()); - return absl::nullopt; + return std::nullopt; } // No more elements from reader. @@ -661,7 +663,7 @@ absl::optional SyncEngine::ReadIntoLoader( LOG_WARN("Failed to AddElement() to bundle loader with error %s", maybe_progress.status().error_message()); result_task.SetError(maybe_progress.status()); - return absl::nullopt; + return std::nullopt; } if (maybe_progress.ValueOrDie().has_value()) { @@ -705,7 +707,7 @@ void SyncEngine::LoadBundle(std::shared_ptr reader, } EmitNewSnapshotsAndNotifyLocalStore(changes.ConsumeValueOrDie(), - absl::nullopt); + std::nullopt); result_task->SetSuccess(SuccessProgress(bundle_metadata)); } diff --git a/Firestore/core/src/core/transaction.cc b/Firestore/core/src/core/transaction.cc index cb14ea656c1..833e78c479b 100644 --- a/Firestore/core/src/core/transaction.cc +++ b/Firestore/core/src/core/transaction.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -65,7 +66,7 @@ Status Transaction::RecordVersion(const Document& doc) { HARD_FAIL("Unexpected document type in transaction: %s", doc.ToString()); } - absl::optional existing_version = GetVersion(doc->key()); + std::optional existing_version = GetVersion(doc->key()); if (existing_version.has_value()) { if (doc_version != existing_version.value()) { // This transaction will fail no matter what. @@ -129,7 +130,7 @@ void Transaction::WriteMutations(std::vector&& mutations) { } Precondition Transaction::CreatePrecondition(const DocumentKey& key) { - absl::optional version = GetVersion(key); + std::optional version = GetVersion(key); if (written_docs_.count(key) == 0 && version.has_value()) { if (version.value() == SnapshotVersion::None()) { return Precondition::Exists(false); @@ -143,7 +144,7 @@ Precondition Transaction::CreatePrecondition(const DocumentKey& key) { StatusOr Transaction::CreateUpdatePrecondition( const DocumentKey& key) { - absl::optional version = GetVersion(key); + std::optional version = GetVersion(key); // The first time a document is written, we want to take into account the // read time and existence. if (written_docs_.count(key) == 0 && version.has_value()) { @@ -243,13 +244,13 @@ void Transaction::EnsureCommitNotCalled() { "update callback has been invoked."); } -absl::optional Transaction::GetVersion( +std::optional Transaction::GetVersion( const DocumentKey& key) const { auto found = read_versions_.find(key); if (found != read_versions_.end()) { return found->second; } - return absl::nullopt; + return std::nullopt; } } // namespace core diff --git a/Firestore/core/src/core/view.cc b/Firestore/core/src/core/view.cc index e1ccb6b838b..fefa34adbba 100644 --- a/Firestore/core/src/core/view.cc +++ b/Firestore/core/src/core/view.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/core/view.h" #include // For std::sort +#include #include #include @@ -39,13 +40,13 @@ using remote::TargetChange; using util::ComparisonResult; // MARK: - Helper Functions for View -absl::optional View::GetLimit(const QueryOrPipeline& query) { +std::optional View::GetLimit(const QueryOrPipeline& query) { if (query.IsPipeline()) { - absl::optional limit = GetLastEffectiveLimit(query.pipeline()); + std::optional limit = GetLastEffectiveLimit(query.pipeline()); if (limit) { return limit; } - return absl::nullopt; + return std::nullopt; } else { const auto& q = query.query(); if (q.has_limit_to_first()) { @@ -53,25 +54,25 @@ absl::optional View::GetLimit(const QueryOrPipeline& query) { } else if (q.has_limit_to_last()) { return -q.limit(); // Negative to indicate limitToLast } - return absl::nullopt; + return std::nullopt; } } LimitType View::GetLimitType(const QueryOrPipeline& query) { if (query.IsPipeline()) { - absl::optional limit = GetLastEffectiveLimit(query.pipeline()); + std::optional limit = GetLastEffectiveLimit(query.pipeline()); return limit > 0 ? LimitType::First : LimitType::Last; } else { return query.query().limit_type(); } } -std::pair, absl::optional> +std::pair, std::optional> View::GetLimitEdges(const QueryOrPipeline& query, const model::DocumentSet& old_document_set) { - absl::optional limit_opt = GetLimit(query); + std::optional limit_opt = GetLimit(query); if (!limit_opt) { - return {absl::nullopt, absl::nullopt}; + return {std::nullopt, std::nullopt}; } int32_t limit_val = *limit_opt; @@ -81,22 +82,22 @@ View::GetLimitEdges(const QueryOrPipeline& query, // The GetLimit function already encodes this as a negative number. if (limit_val > 0 && old_document_set.size() == static_cast(limit_val)) { - return {old_document_set.GetLastDocument(), absl::nullopt}; + return {old_document_set.GetLastDocument(), std::nullopt}; } else if (limit_val < 0 && old_document_set.size() == static_cast(-limit_val)) { - return {absl::nullopt, old_document_set.GetFirstDocument()}; + return {std::nullopt, old_document_set.GetFirstDocument()}; } } else { const auto& q = query.query(); if (q.has_limit_to_first() && old_document_set.size() == static_cast(q.limit())) { - return {old_document_set.GetLastDocument(), absl::nullopt}; + return {old_document_set.GetLastDocument(), std::nullopt}; } else if (q.has_limit_to_last() && old_document_set.size() == static_cast(q.limit())) { - return {absl::nullopt, old_document_set.GetFirstDocument()}; + return {std::nullopt, old_document_set.GetFirstDocument()}; } } - return {absl::nullopt, absl::nullopt}; + return {std::nullopt, std::nullopt}; } // MARK: - LimboDocumentChange @@ -160,7 +161,7 @@ ComparisonResult View::Compare(const Document& lhs, const Document& rhs) const { ViewDocumentChanges View::ComputeDocumentChanges( const DocumentMap& doc_changes, - const absl::optional& previous_changes) const { + const std::optional& previous_changes) const { DocumentViewChangeSet change_set; if (previous_changes) { change_set = previous_changes->change_set(); @@ -175,16 +176,16 @@ ViewDocumentChanges View::ComputeDocumentChanges( bool needs_refill = false; auto limit_edges = GetLimitEdges(query_, old_document_set); - absl::optional last_doc_in_limit = limit_edges.first; - absl::optional first_doc_in_limit = limit_edges.second; + std::optional last_doc_in_limit = limit_edges.first; + std::optional first_doc_in_limit = limit_edges.second; for (const auto& kv : doc_changes) { const DocumentKey& key = kv.first; - absl::optional old_doc = old_document_set.GetDocument(key); - absl::optional new_doc = query_.Matches(kv.second) - ? absl::optional{kv.second} - : absl::nullopt; + std::optional old_doc = old_document_set.GetDocument(key); + std::optional new_doc = query_.Matches(kv.second) + ? std::optional{kv.second} + : std::nullopt; bool old_doc_had_pending_mutations = old_doc && old_mutated_keys.contains(key); @@ -291,7 +292,7 @@ ViewDocumentChanges View::ComputeDocumentChanges( auto abs_limit = std::abs(limit.value()); if (abs_limit < static_cast(new_document_set.size())) { for (size_t i = new_document_set.size() - abs_limit; i > 0; --i) { - absl::optional found = + std::optional found = limit_type == LimitType::First ? new_document_set.GetLastDocument() : new_document_set.GetFirstDocument(); @@ -327,7 +328,7 @@ bool View::ShouldWaitForSyncedDocument(const Document& new_doc, } ViewChange View::ApplyChanges(const ViewDocumentChanges& doc_changes, - const absl::optional& target_change, + const std::optional& target_change, bool targetIsPendingReset) { HARD_ASSERT(!doc_changes.needs_refill(), "Cannot apply changes that need a refill"); @@ -365,7 +366,7 @@ ViewChange View::ApplyChanges(const ViewDocumentChanges& doc_changes, if (changes.empty() && !sync_state_changed) { // No changes. - return ViewChange(absl::nullopt, std::move(limbo_changes)); + return ViewChange(std::nullopt, std::move(limbo_changes)); } else { bool has_cached_results = target_change.has_value() && !target_change->resume_token().empty(); @@ -395,7 +396,7 @@ ViewChange View::ApplyOnlineStateChange(OnlineState online_state) { mutated_keys_, /* needs_refill= */ false)); } else { // No effect, just return a no-op ViewChange. - return ViewChange(absl::nullopt, {}); + return ViewChange(std::nullopt, {}); } } @@ -426,7 +427,7 @@ bool View::ShouldBeInLimbo(const DocumentKey& key) const { * Updates synced_documents_ and current based on the given change. */ void View::ApplyTargetChange( - const absl::optional& maybe_target_change) { + const std::optional& maybe_target_change) { if (maybe_target_change.has_value()) { const TargetChange& target_change = maybe_target_change.value(); diff --git a/Firestore/core/src/local/leveldb_bundle_cache.cc b/Firestore/core/src/local/leveldb_bundle_cache.cc index 9af27373b34..a8c9c08cc16 100644 --- a/Firestore/core/src/local/leveldb_bundle_cache.cc +++ b/Firestore/core/src/local/leveldb_bundle_cache.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/local/leveldb_bundle_cache.h" +#include #include #include "Firestore/core/src/bundle/bundle_metadata.h" @@ -39,14 +40,14 @@ LevelDbBundleCache::LevelDbBundleCache(LevelDbPersistence* db, : db_(NOT_NULL(db)), serializer_(NOT_NULL(serializer)) { } -absl::optional LevelDbBundleCache::GetBundleMetadata( +std::optional LevelDbBundleCache::GetBundleMetadata( const std::string& bundle_id) const { auto key = LevelDbBundleKey::Key(bundle_id); std::string encoded; auto done = db_->current_transaction()->Get(key, &encoded); if (!done.ok()) { - return absl::nullopt; + return std::nullopt; } nanopb::StringReader reader{encoded}; @@ -61,7 +62,7 @@ absl::optional LevelDbBundleCache::GetBundleMetadata( HARD_FAIL("BundleMetadata proto failed to decode: %s", reader.status().ToString()); } - return absl::make_optional(std::move(bundle)); + return std::make_optional(std::move(bundle)); } void LevelDbBundleCache::SaveBundleMetadata(const BundleMetadata& metadata) { @@ -69,14 +70,14 @@ void LevelDbBundleCache::SaveBundleMetadata(const BundleMetadata& metadata) { db_->current_transaction()->Put(key, serializer_->EncodeBundle(metadata)); } -absl::optional LevelDbBundleCache::GetNamedQuery( +std::optional LevelDbBundleCache::GetNamedQuery( const std::string& query_name) const { auto key = LevelDbNamedQueryKey::Key(query_name); std::string encoded; auto done = db_->current_transaction()->Get(key, &encoded); if (!done.ok()) { - return absl::nullopt; + return std::nullopt; } nanopb::StringReader reader{encoded}; @@ -91,7 +92,7 @@ absl::optional LevelDbBundleCache::GetNamedQuery( HARD_FAIL("NamedQuery proto failed to decode: %s", reader.status().ToString()); } - return absl::make_optional(std::move(named_query)); + return std::make_optional(std::move(named_query)); } void LevelDbBundleCache::SaveNamedQuery(const NamedQuery& query) { diff --git a/Firestore/core/src/local/leveldb_document_overlay_cache.cc b/Firestore/core/src/local/leveldb_document_overlay_cache.cc index 80588e8d2ae..bae21d2291b 100644 --- a/Firestore/core/src/local/leveldb_document_overlay_cache.cc +++ b/Firestore/core/src/local/leveldb_document_overlay_cache.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/local/leveldb_document_overlay_cache.h" +#include #include #include @@ -28,7 +29,6 @@ #include "Firestore/core/src/util/hard_assert.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace firebase { namespace firestore { @@ -52,7 +52,7 @@ LevelDbDocumentOverlayCache::LevelDbDocumentOverlayCache( user_id_(user.is_authenticated() ? user.uid() : "") { } -absl::optional LevelDbDocumentOverlayCache::GetOverlay( +std::optional LevelDbDocumentOverlayCache::GetOverlay( const DocumentKey& document_key) const { const std::string key_prefix = LevelDbDocumentOverlayKey::KeyPrefix(user_id_, document_key); @@ -61,13 +61,13 @@ absl::optional LevelDbDocumentOverlayCache::GetOverlay( it->Seek(key_prefix); if (!it->Valid() || !absl::StartsWith(it->key(), key_prefix)) { - return absl::nullopt; + return std::nullopt; } LevelDbDocumentOverlayKey key; HARD_ASSERT(key.Decode(it->key())); if (key.document_key() != document_key) { - return absl::nullopt; + return std::nullopt; } return ParseOverlay(key, it->value()); @@ -90,7 +90,7 @@ OverlayByDocumentKeyMap LevelDbDocumentOverlayCache::GetOverlays( OverlayByDocumentKeyMap result; ForEachKeyInCollection( collection, since_batch_id, [&](LevelDbDocumentOverlayKey&& key) { - absl::optional overlay = GetOverlay(key); + std::optional overlay = GetOverlay(key); HARD_ASSERT(overlay.has_value()); result[std::move(key).document_key()] = std::move(overlay).value(); }); @@ -101,7 +101,7 @@ OverlayByDocumentKeyMap LevelDbDocumentOverlayCache::GetOverlays( absl::string_view collection_group, int since_batch_id, std::size_t count) const { - absl::optional current_batch_id; + std::optional current_batch_id; OverlayByDocumentKeyMap result; ForEachKeyInCollectionGroup( collection_group, since_batch_id, @@ -115,7 +115,7 @@ OverlayByDocumentKeyMap LevelDbDocumentOverlayCache::GetOverlays( current_batch_id = key.largest_batch_id(); } - absl::optional overlay = GetOverlay(key); + std::optional overlay = GetOverlay(key); HARD_ASSERT(overlay.has_value()); result[std::move(key).document_key()] = std::move(overlay).value(); return ForEachKeyAction::kKeepGoing; @@ -180,7 +180,7 @@ void LevelDbDocumentOverlayCache::SaveOverlay(int largest_batch_id, transaction->Put(LevelDbDocumentOverlayLargestBatchIdIndexKey::Key(key), ""); transaction->Put(LevelDbDocumentOverlayCollectionIndexKey::Key(key), ""); - absl::optional collection_group_index_key = + std::optional collection_group_index_key = LevelDbDocumentOverlayCollectionGroupIndexKey::Key(key); if (collection_group_index_key.has_value()) { transaction->Put(std::move(collection_group_index_key).value(), ""); @@ -212,7 +212,7 @@ void LevelDbDocumentOverlayCache::DeleteOverlay( transaction->Delete(LevelDbDocumentOverlayLargestBatchIdIndexKey::Key(key)); transaction->Delete(LevelDbDocumentOverlayCollectionIndexKey::Key(key)); - absl::optional collection_group_index_key = + std::optional collection_group_index_key = LevelDbDocumentOverlayCollectionGroupIndexKey::Key(key); if (collection_group_index_key.has_value()) { transaction->Delete(std::move(collection_group_index_key).value()); @@ -287,13 +287,13 @@ void LevelDbDocumentOverlayCache::ForEachKeyInCollectionGroup( } } -absl::optional LevelDbDocumentOverlayCache::GetOverlay( +std::optional LevelDbDocumentOverlayCache::GetOverlay( const LevelDbDocumentOverlayKey& key) const { auto it = db_->current_transaction()->NewIterator(); const std::string encoded_key = key.Encode(); it->Seek(encoded_key); if (!it->Valid() || it->key() != encoded_key) { - return absl::nullopt; + return std::nullopt; } return ParseOverlay(key, it->value()); } diff --git a/Firestore/core/src/local/leveldb_index_manager.cc b/Firestore/core/src/local/leveldb_index_manager.cc index 0455bf88898..e62a0da7bd7 100644 --- a/Firestore/core/src/local/leveldb_index_manager.cc +++ b/Firestore/core/src/local/leveldb_index_manager.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -439,7 +440,7 @@ std::vector LevelDbIndexManager::GetFieldIndexes() const { return result; } -absl::optional LevelDbIndexManager::GetFieldIndex( +std::optional LevelDbIndexManager::GetFieldIndex( const core::Target& target) const { HARD_ASSERT(started_, "IndexManager not started"); @@ -451,10 +452,10 @@ absl::optional LevelDbIndexManager::GetFieldIndex( std::vector collection_indexes = GetFieldIndexes(collection_group); if (collection_indexes.empty()) { - return absl::nullopt; + return std::nullopt; } - absl::optional result; + std::optional result; for (FieldIndex index : collection_indexes) { if (target_index_matcher.ServedByIndex(index)) { if (!result.has_value() || @@ -540,7 +541,7 @@ IndexManager::IndexType LevelDbIndexManager::GetIndexType( const auto sub_targets = GetSubTargets(target); for (const Target& sub_target : sub_targets) { - absl::optional index = GetFieldIndex(sub_target); + std::optional index = GetFieldIndex(sub_target); if (!index) { result = IndexManager::IndexType::NONE; break; @@ -563,13 +564,13 @@ IndexManager::IndexType LevelDbIndexManager::GetIndexType( return result; } -absl::optional> +std::optional> LevelDbIndexManager::GetDocumentsMatchingTarget(const core::Target& target) { std::vector> indexes; for (const auto& sub_target : GetSubTargets(target)) { auto index_opt = GetFieldIndex(sub_target); if (!index_opt.has_value()) { - return absl::nullopt; + return std::nullopt; } indexes.emplace_back(sub_target, index_opt.value()); } @@ -754,10 +755,10 @@ std::vector LevelDbIndexManager::CreateRange( return ranges; } -absl::optional -LevelDbIndexManager::GetNextCollectionGroupToUpdate() const { +std::optional LevelDbIndexManager::GetNextCollectionGroupToUpdate() + const { if (next_index_to_update_.empty()) { - return absl::nullopt; + return std::nullopt; } return next_index_to_update_.top()->collection_group(); @@ -832,7 +833,7 @@ std::set LevelDbIndexManager::ComputeIndexEntries( std::set results; auto directional_value = EncodeDirectionalElements(index, document); - if (directional_value == absl::nullopt) { + if (directional_value == std::nullopt) { return results; } @@ -858,13 +859,13 @@ std::set LevelDbIndexManager::ComputeIndexEntries( return results; } -absl::optional LevelDbIndexManager::EncodeDirectionalElements( +std::optional LevelDbIndexManager::EncodeDirectionalElements( const FieldIndex& index, const model::Document& document) { IndexEncodingBuffer index_buffer; for (const auto& segment : index.GetDirectionalSegments()) { auto field = document->field(segment.field_path()); if (!field.has_value()) { - return absl::nullopt; + return std::nullopt; } index::WriteIndexValue(field.value(), index_buffer.ForKind(segment.kind())); } diff --git a/Firestore/core/src/local/leveldb_mutation_queue.cc b/Firestore/core/src/local/leveldb_mutation_queue.cc index b21d0f1bfe4..01e36f415ae 100644 --- a/Firestore/core/src/local/leveldb_mutation_queue.cc +++ b/Firestore/core/src/local/leveldb_mutation_queue.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/local/leveldb_mutation_queue.h" #include +#include #include #include "Firestore/core/src/core/query.h" @@ -332,7 +333,7 @@ LevelDbMutationQueue::AllMutationBatchesAffectingQuery(const Query& query) { return AllMutationBatchesWithIds(unique_batch_ids); } -absl::optional LevelDbMutationQueue::LookupMutationBatch( +std::optional LevelDbMutationQueue::LookupMutationBatch( model::BatchId batch_id) { std::string key = mutation_batch_key(batch_id); @@ -340,7 +341,7 @@ absl::optional LevelDbMutationQueue::LookupMutationBatch( Status status = db_->current_transaction()->Get(key, &value); if (!status.ok()) { if (status.IsNotFound()) { - return absl::nullopt; + return std::nullopt; } HARD_FAIL("Lookup mutation batch (%s, %s) failed with status: %s", user_id_, batch_id, status.ToString()); @@ -349,7 +350,7 @@ absl::optional LevelDbMutationQueue::LookupMutationBatch( return ParseMutationBatch(value); } -absl::optional +std::optional LevelDbMutationQueue::NextMutationBatchAfterBatchId(model::BatchId batch_id) { BatchId next_batch_id = batch_id + 1; @@ -360,12 +361,12 @@ LevelDbMutationQueue::NextMutationBatchAfterBatchId(model::BatchId batch_id) { LevelDbMutationKey row_key; if (!it->Valid() || !row_key.Decode(it->key())) { // Past the last row in the DB or out of the mutations table - return absl::nullopt; + return std::nullopt; } if (row_key.user_id() != user_id_) { // Jumped past the last mutation for this user - return absl::nullopt; + return std::nullopt; } HARD_ASSERT(row_key.batch_id() >= next_batch_id, diff --git a/Firestore/core/src/local/leveldb_target_cache.cc b/Firestore/core/src/local/leveldb_target_cache.cc index bcdd1d32876..e83cff38fb5 100644 --- a/Firestore/core/src/local/leveldb_target_cache.cc +++ b/Firestore/core/src/local/leveldb_target_cache.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/local/leveldb_target_cache.h" +#include #include #include #include @@ -48,7 +49,7 @@ using model::TargetId; using nanopb::Message; using nanopb::StringReader; -absl::optional> +std::optional> LevelDbTargetCache::TryReadMetadata(leveldb::DB* db) { std::string key = LevelDbTargetGlobalKey::Key(); std::string value; @@ -60,7 +61,7 @@ LevelDbTargetCache::TryReadMetadata(leveldb::DB* db) { auto result = Message::TryParse(&reader); if (!reader.ok()) { if (reader.status().code() == Error::kErrorNotFound) { - return absl::nullopt; + return std::nullopt; } else { HARD_FAIL("ReadMetadata: failed loading key %s with status: %s", key, reader.status().ToString()); @@ -138,7 +139,7 @@ void LevelDbTargetCache::RemoveTarget(const TargetData& target_data) { SaveMetadata(); } -absl::optional LevelDbTargetCache::GetTarget( +std::optional LevelDbTargetCache::GetTarget( const core::TargetOrPipeline& target_or_pipeline) { // Scan the query-target index starting with a prefix starting with the given // target's or pipeline's canonical_id. Note that this is a scan rather than @@ -190,7 +191,7 @@ absl::optional LevelDbTargetCache::GetTarget( } } - return absl::nullopt; + return std::nullopt; } void LevelDbTargetCache::EnumerateSequenceNumbers( diff --git a/Firestore/core/src/local/memory_bundle_cache.cc b/Firestore/core/src/local/memory_bundle_cache.cc index 6637afb3dd1..b04c2eab722 100644 --- a/Firestore/core/src/local/memory_bundle_cache.cc +++ b/Firestore/core/src/local/memory_bundle_cache.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/local/memory_bundle_cache.h" +#include #include namespace firebase { @@ -25,26 +26,26 @@ namespace local { using bundle::BundleMetadata; using bundle::NamedQuery; -absl::optional MemoryBundleCache::GetBundleMetadata( +std::optional MemoryBundleCache::GetBundleMetadata( const std::string& bundle_id) const { auto got = bundles_.find(bundle_id); if (got == bundles_.end()) { - return absl::nullopt; + return std::nullopt; } - return absl::make_optional(got->second); + return std::make_optional(got->second); } void MemoryBundleCache::SaveBundleMetadata(const BundleMetadata& metadata) { bundles_[metadata.bundle_id()] = metadata; } -absl::optional MemoryBundleCache::GetNamedQuery( +std::optional MemoryBundleCache::GetNamedQuery( const std::string& query_name) const { auto got = named_queries_.find(query_name); if (got == named_queries_.end()) { - return absl::nullopt; + return std::nullopt; } - return absl::make_optional(got->second); + return std::make_optional(got->second); } void MemoryBundleCache::SaveNamedQuery(const NamedQuery& query) { diff --git a/Firestore/core/src/local/memory_document_overlay_cache.cc b/Firestore/core/src/local/memory_document_overlay_cache.cc index ede9cf4ab38..3002d9b7a99 100644 --- a/Firestore/core/src/local/memory_document_overlay_cache.cc +++ b/Firestore/core/src/local/memory_document_overlay_cache.cc @@ -18,6 +18,7 @@ #include #include +#include #include "Firestore/core/src/util/hard_assert.h" @@ -33,11 +34,11 @@ using model::Overlay; using model::OverlayByDocumentKeyMap; using model::ResourcePath; -absl::optional MemoryDocumentOverlayCache::GetOverlay( +std::optional MemoryDocumentOverlayCache::GetOverlay( const DocumentKey& key) const { const auto overlays_iter = overlays_.find(key); if (overlays_iter == overlays_.end()) { - return absl::nullopt; + return std::nullopt; } else { return overlays_iter->second; } diff --git a/Firestore/core/src/local/memory_index_manager.cc b/Firestore/core/src/local/memory_index_manager.cc index 9789a918950..3858486d3d7 100644 --- a/Firestore/core/src/local/memory_index_manager.cc +++ b/Firestore/core/src/local/memory_index_manager.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/local/memory_index_manager.h" #include +#include #include #include #include @@ -107,15 +108,15 @@ IndexManager::IndexType MemoryIndexManager::GetIndexType(const core::Target&) { return IndexManager::IndexType::NONE; } -absl::optional> +std::optional> MemoryIndexManager::GetDocumentsMatchingTarget(const core::Target&) { // Field indices are not supported with memory persistence. - return absl::nullopt; + return std::nullopt; } -absl::optional MemoryIndexManager::GetNextCollectionGroupToUpdate() +std::optional MemoryIndexManager::GetNextCollectionGroupToUpdate() const { - return absl::nullopt; + return std::nullopt; } void MemoryIndexManager::UpdateCollectionGroup(const std::string&, diff --git a/Firestore/core/src/local/memory_mutation_queue.cc b/Firestore/core/src/local/memory_mutation_queue.cc index 3fc4866c1c3..0df7c5b4104 100644 --- a/Firestore/core/src/local/memory_mutation_queue.cc +++ b/Firestore/core/src/local/memory_mutation_queue.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/local/memory_mutation_queue.h" +#include #include #include "Firestore/core/src/core/query.h" @@ -207,8 +208,8 @@ MemoryMutationQueue::AllMutationBatchesAffectingQuery(const Query& query) { return AllMutationBatchesWithIds(unique_batch_ids); } -absl::optional -MemoryMutationQueue::NextMutationBatchAfterBatchId(BatchId batch_id) { +std::optional MemoryMutationQueue::NextMutationBatchAfterBatchId( + BatchId batch_id) { BatchId next_batch_id = batch_id + 1; // The requested batch_id may still be out of range so normalize it to the @@ -216,7 +217,7 @@ MemoryMutationQueue::NextMutationBatchAfterBatchId(BatchId batch_id) { int raw_index = IndexOfBatchId(next_batch_id); size_t index = raw_index < 0 ? 0 : static_cast(raw_index); if (queue_.size() <= index) { - return absl::nullopt; + return std::nullopt; } return queue_[index]; @@ -226,15 +227,15 @@ BatchId MemoryMutationQueue::GetHighestUnacknowledgedBatchId() { return IsEmpty() ? kBatchIdUnknown : next_batch_id_ - 1; } -absl::optional MemoryMutationQueue::LookupMutationBatch( +std::optional MemoryMutationQueue::LookupMutationBatch( BatchId batch_id) { if (queue_.empty()) { - return absl::nullopt; + return std::nullopt; } int index = IndexOfBatchId(batch_id); if (index < 0 || static_cast(index) >= queue_.size()) { - return absl::nullopt; + return std::nullopt; } const MutationBatch& batch = queue_[index]; diff --git a/Firestore/core/src/model/document_key.cc b/Firestore/core/src/model/document_key.cc index f57c5502864..131a38b5c0b 100644 --- a/Firestore/core/src/model/document_key.cc +++ b/Firestore/core/src/model/document_key.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/model/document_key.h" +#include #include #include @@ -113,10 +114,10 @@ bool DocumentKey::HasCollectionGroup(absl::string_view collection_group) const { collection_id_opt.value() == collection_group; } -absl::optional DocumentKey::GetCollectionGroup() const { +std::optional DocumentKey::GetCollectionGroup() const { const size_t size = path().size(); if (size < 2) { - return absl::nullopt; + return std::nullopt; } return path()[size - 2]; } diff --git a/Firestore/core/src/model/field_index.cc b/Firestore/core/src/model/field_index.cc index 4cf58e4d988..6f512a7b5f3 100644 --- a/Firestore/core/src/model/field_index.cc +++ b/Firestore/core/src/model/field_index.cc @@ -16,6 +16,8 @@ #include "Firestore/core/src/model/field_index.h" +#include + namespace firebase { namespace firestore { namespace model { @@ -118,7 +120,7 @@ util::ComparisonResult FieldIndex::SemanticCompare(const FieldIndex& left, return util::ComparisonResult::Same; } -absl::optional FieldIndex::GetArraySegment() const { +std::optional FieldIndex::GetArraySegment() const { for (const auto& segment : segments_) { if (segment.kind() == Segment::kContains) { // Firestore queries can only have a single ArrayContains/ArrayContainsAny @@ -126,7 +128,7 @@ absl::optional FieldIndex::GetArraySegment() const { return segment; } } - return absl::nullopt; + return std::nullopt; } } // namespace model diff --git a/Firestore/core/src/model/object_value.cc b/Firestore/core/src/model/object_value.cc index a72a9c8efa1..d7075cad0f4 100644 --- a/Firestore/core/src/model/object_value.cc +++ b/Firestore/core/src/model/object_value.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -262,7 +263,7 @@ FieldMask ObjectValue::ExtractFieldMask( return FieldMask(std::move(fields)); } -absl::optional ObjectValue::Get( +std::optional ObjectValue::Get( const FieldPath& path) const { if (path.empty()) { return *value_; @@ -272,16 +273,16 @@ absl::optional ObjectValue::Get( for (const std::string& segment : path) { google_firestore_v1_MapValue_FieldsEntry* entry = FindEntry(nested_value, segment); - if (!entry) return absl::nullopt; + if (!entry) return std::nullopt; nested_value = entry->value; } return nested_value; } -absl::optional ObjectValue::Get( +std::optional ObjectValue::Get( const std::string& key) const { google_firestore_v1_MapValue_FieldsEntry* entry = FindEntry(*value_, key); - if (!entry) return absl::nullopt; + if (!entry) return std::nullopt; return entry->value; } @@ -309,7 +310,7 @@ void ObjectValue::SetAll(TransformMap data) { for (auto& it : data) { const FieldPath& path = it.first; - absl::optional> value = + std::optional> value = std::move(it.second); if (!parent.IsImmediateParentOf(path)) { diff --git a/Firestore/core/src/model/patch_mutation.cc b/Firestore/core/src/model/patch_mutation.cc index abc5716b7f6..786bcb1fcf3 100644 --- a/Firestore/core/src/model/patch_mutation.cc +++ b/Firestore/core/src/model/patch_mutation.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/model/patch_mutation.h" #include +#include #include #include @@ -96,9 +97,9 @@ void PatchMutation::Rep::ApplyToRemoteDocument( .SetHasCommittedMutations(); } -absl::optional PatchMutation::Rep::ApplyToLocalView( +std::optional PatchMutation::Rep::ApplyToLocalView( MutableDocument& document, - absl::optional previous_mask, + std::optional previous_mask, const Timestamp& local_write_time) const { VerifyKeyMatches(document); @@ -113,7 +114,7 @@ absl::optional PatchMutation::Rep::ApplyToLocalView( document.ConvertToFoundDocument(document.version()).SetHasLocalMutations(); if (!previous_mask.has_value()) { - return absl::nullopt; + return std::nullopt; } std::set merged_set(previous_mask.value().begin(), @@ -134,7 +135,7 @@ TransformMap PatchMutation::Rep::GetPatch() const { if (value) { result[path] = DeepClone(*value); } else { - result[path] = absl::nullopt; + result[path] = std::nullopt; } } } diff --git a/Firestore/core/src/model/server_timestamp_util.cc b/Firestore/core/src/model/server_timestamp_util.cc index 80a413d9a5d..8eddead7d78 100644 --- a/Firestore/core/src/model/server_timestamp_util.cc +++ b/Firestore/core/src/model/server_timestamp_util.cc @@ -16,6 +16,8 @@ #include "Firestore/core/src/model/server_timestamp_util.h" +#include + #include "Firestore/core/src/model/value_util.h" #include "Firestore/core/src/nanopb/nanopb_util.h" #include "Firestore/core/src/util/hard_assert.h" @@ -34,7 +36,7 @@ const char kServerTimestampSentinel[] = "server_timestamp"; Message EncodeServerTimestamp( const Timestamp& local_write_time, - absl::optional previous_value) { + std::optional previous_value) { // We should avoid storing deeply nested server timestamp map values // because we never use the intermediate "previous values". // For example: @@ -112,7 +114,7 @@ google_protobuf_Timestamp GetLocalWriteTime( HARD_FAIL("LocalWriteTime not found"); } -absl::optional GetPreviousValue( +std::optional GetPreviousValue( const google_firestore_v1_Value& value) { for (size_t i = 0; i < value.map_value.fields_count; ++i) { const auto& field = value.map_value.fields[i]; @@ -126,7 +128,7 @@ absl::optional GetPreviousValue( } } - return absl::nullopt; + return std::nullopt; } } // namespace model diff --git a/Firestore/core/src/model/transform_operation.cc b/Firestore/core/src/model/transform_operation.cc index 5ad18958072..0d663f23849 100644 --- a/Firestore/core/src/model/transform_operation.cc +++ b/Firestore/core/src/model/transform_operation.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -71,21 +72,21 @@ class ServerTimestampTransform::Rep : public TransformOperation::Rep { } Message ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& local_write_time) const override { return EncodeServerTimestamp(local_write_time, previous_value); } Message ApplyToRemoteDocument( - const absl::optional&, + const std::optional&, Message transform_result) const override { return transform_result; } - absl::optional> ComputeBaseValue( - const absl::optional&) const override { + std::optional> ComputeBaseValue( + const std::optional&) const override { // Server timestamps are idempotent and don't require a base value. - return absl::nullopt; + return std::nullopt; } bool Equals(const TransformOperation::Rep& other) const override { @@ -127,13 +128,13 @@ class ArrayTransform::Rep : public TransformOperation::Rep { } Message ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp&) const override { return Apply(previous_value); } Message ApplyToRemoteDocument( - const absl::optional& previous_value, + const std::optional& previous_value, Message) const override { // The server just sends null as the transform result for array operations, // so we have to calculate a result the same as we do for local @@ -141,10 +142,10 @@ class ArrayTransform::Rep : public TransformOperation::Rep { return Apply(previous_value); } - absl::optional> ComputeBaseValue( - const absl::optional&) const override { + std::optional> ComputeBaseValue( + const std::optional&) const override { // Array transforms are idempotent and don't require a base value. - return absl::nullopt; + return std::nullopt; } google_firestore_v1_ArrayValue elements() const { @@ -166,10 +167,10 @@ class ArrayTransform::Rep : public TransformOperation::Rep { * google_firestore_v1_Value. */ Message CoercedFieldValueArray( - const absl::optional& value) const; + const std::optional& value) const; Message Apply( - const absl::optional& previous_value) const; + const std::optional& previous_value) const; Type type_; nanopb::Message elements_; @@ -238,7 +239,7 @@ std::string ArrayTransform::Rep::ToString() const { Message ArrayTransform::Rep::CoercedFieldValueArray( - const absl::optional& value) const { + const std::optional& value) const { if (IsArray(value)) { return DeepClone(value->array_value); } else { @@ -248,7 +249,7 @@ ArrayTransform::Rep::CoercedFieldValueArray( } Message ArrayTransform::Rep::Apply( - const absl::optional& previous_value) const { + const std::optional& previous_value) const { Message array_value = CoercedFieldValueArray(previous_value); if (type_ == Type::ArrayUnion) { @@ -390,14 +391,14 @@ class NumericTransform::Rep : public TransformOperation::Rep { } Message ApplyToRemoteDocument( - const absl::optional&, + const std::optional&, Message transform_result) const override { return transform_result; } - absl::optional> ComputeBaseValue( - const absl::optional&) const override { - return absl::nullopt; + std::optional> ComputeBaseValue( + const std::optional&) const override { + return std::nullopt; } double OperandAsDouble() const { @@ -454,11 +455,11 @@ class NumericIncrementTransform::Rep : public NumericTransform::Rep { } Message ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& local_write_time) const override; - absl::optional> ComputeBaseValue( - const absl::optional& previous_value) + std::optional> ComputeBaseValue( + const std::optional& previous_value) const override { if (IsNumber(previous_value)) { return DeepClone(*previous_value); @@ -502,7 +503,7 @@ class NumericMinimumTransform::Rep : public NumericTransform::Rep { } Message ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& local_write_time) const override; std::string ToString() const override { @@ -536,7 +537,7 @@ class NumericMaximumTransform::Rep : public NumericTransform::Rep { } Message ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& local_write_time) const override; std::string ToString() const override { @@ -558,7 +559,7 @@ NumericMaximumTransform::NumericMaximumTransform(const TransformOperation& op) Message NumericIncrementTransform::Rep::ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& /* local_write_time */) const { auto base_value = ComputeBaseValue(previous_value); HARD_ASSERT(base_value.has_value() && IsNumber(**base_value), @@ -637,7 +638,7 @@ NumericIncrementTransform::Rep::ApplyToLocalView( Message NumericMinimumTransform::Rep::ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& /* local_write_time */) const { if (!IsNumber(previous_value)) { return DeepClone(*operand_); @@ -657,7 +658,7 @@ NumericMinimumTransform::Rep::ApplyToLocalView( Message NumericMaximumTransform::Rep::ApplyToLocalView( - const absl::optional& previous_value, + const std::optional& previous_value, const Timestamp& /* local_write_time */) const { if (!IsNumber(previous_value)) { return DeepClone(*operand_); diff --git a/Firestore/core/src/remote/datastore.cc b/Firestore/core/src/remote/datastore.cc index c8b58e09325..b95e5e8aa97 100644 --- a/Firestore/core/src/remote/datastore.cc +++ b/Firestore/core/src/remote/datastore.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/remote/datastore.h" +#include #include #include #include @@ -380,8 +381,8 @@ void Datastore::ResumeRpcWithCredentials(const OnCredentials& on_credentials) { auto credentials = std::make_shared(); auto done = [weak_this, credentials, on_credentials]( - const absl::optional>& auth, - const absl::optional& app_check) { + const std::optional>& auth, + const std::optional& app_check) { auto strong_this = weak_this.lock(); if (!strong_this) { return; @@ -421,11 +422,11 @@ void Datastore::ResumeRpcWithCredentials(const OnCredentials& on_credentials) { }; auth_credentials_->GetToken( - [done](const StatusOr& auth) { done(auth, absl::nullopt); }); + [done](const StatusOr& auth) { done(auth, std::nullopt); }); app_check_credentials_->GetToken( [done](const StatusOr& app_check) { - done(absl::nullopt, app_check.ValueOrDie()); // AppCheck never fails + done(std::nullopt, app_check.ValueOrDie()); // AppCheck never fails }); } diff --git a/Firestore/core/src/remote/grpc_stream.cc b/Firestore/core/src/remote/grpc_stream.cc index 5101c36fb64..9f7269ed401 100644 --- a/Firestore/core/src/remote/grpc_stream.cc +++ b/Firestore/core/src/remote/grpc_stream.cc @@ -18,6 +18,7 @@ #include #include +#include #include "Firestore/core/src/remote/grpc_connection.h" #include "Firestore/core/src/remote/grpc_util.h" @@ -57,15 +58,15 @@ using Type = GrpcCompletion::Type; namespace internal { -absl::optional BufferedWriter::EnqueueWrite( +std::optional BufferedWriter::EnqueueWrite( grpc::ByteBuffer&& message, const grpc::WriteOptions& options) { queue_.push({std::move(message), options}); return TryStartWrite(); } -absl::optional BufferedWriter::TryStartWrite() { +std::optional BufferedWriter::TryStartWrite() { if (queue_.empty() || has_active_write_) { - return absl::nullopt; + return std::nullopt; } has_active_write_ = true; @@ -74,7 +75,7 @@ absl::optional BufferedWriter::TryStartWrite() { return {std::move(message)}; } -absl::optional BufferedWriter::DequeueNextWrite() { +std::optional BufferedWriter::DequeueNextWrite() { has_active_write_ = false; return TryStartWrite(); } @@ -145,7 +146,7 @@ void GrpcStream::WriteLast(grpc::ByteBuffer&& message) { MaybeWrite(buffered_writer_.EnqueueWrite(std::move(message), options)); } -void GrpcStream::MaybeWrite(absl::optional maybe_write) { +void GrpcStream::MaybeWrite(std::optional maybe_write) { if (!maybe_write) { return; } @@ -261,7 +262,7 @@ bool GrpcStream::WriteAndFinish(grpc::ByteBuffer&& message) { } bool GrpcStream::TryLastWrite(grpc::ByteBuffer&& message) { - absl::optional maybe_write = + std::optional maybe_write = buffered_writer_.EnqueueWrite(std::move(message)); // Only bother with the last write if there is no active write at the moment. if (!maybe_write) { diff --git a/Firestore/core/src/remote/remote_event.cc b/Firestore/core/src/remote/remote_event.cc index 88a72991798..9b172aecadb 100644 --- a/Firestore/core/src/remote/remote_event.cc +++ b/Firestore/core/src/remote/remote_event.cc @@ -16,6 +16,7 @@ #include "Firestore/core/src/remote/remote_event.h" +#include #include #include @@ -219,9 +220,9 @@ create_existence_filter_mismatch_info_for_testing_hooks( int local_cache_count, const ExistenceFilterWatchChange& existence_filter, const DatabaseId& database_id, - absl::optional bloom_filter, + std::optional bloom_filter, BloomFilterApplicationStatus status) { - absl::optional bloom_filter_info; + std::optional bloom_filter_info; if (existence_filter.filter().bloom_filter_parameters().has_value()) { const BloomFilterParameters& bloom_filter_parameters = existence_filter.filter().bloom_filter_parameters().value(); @@ -237,7 +238,7 @@ create_existence_filter_mismatch_info_for_testing_hooks( std::move(bloom_filter_info)}; } -absl::optional GetSingleDocumentPath( +std::optional GetSingleDocumentPath( const core::TargetOrPipeline target_or_pipeline) { if (target_or_pipeline.IsPipeline()) { if (core::GetPipelineSourceType(target_or_pipeline.pipeline()) == @@ -252,10 +253,10 @@ absl::optional GetSingleDocumentPath( return target_or_pipeline.target().path(); } - return absl::nullopt; + return std::nullopt; } -absl::optional> GetDocumentPaths( +std::optional> GetDocumentPaths( const core::TargetOrPipeline target_or_pipeline) { if (target_or_pipeline.IsPipeline()) { if (core::GetPipelineSourceType(target_or_pipeline.pipeline()) == @@ -274,7 +275,7 @@ absl::optional> GetDocumentPaths( return std::vector{target_or_pipeline.target().path()}; } - return absl::nullopt; + return std::nullopt; } } // namespace @@ -284,7 +285,7 @@ void WatchChangeAggregator::HandleExistenceFilter( TargetId target_id = existence_filter.target_id(); int expected_count = existence_filter.filter().count(); - absl::optional target_data = TargetDataForActiveTarget(target_id); + std::optional target_data = TargetDataForActiveTarget(target_id); if (target_data) { const core::TargetOrPipeline& target_or_pipeline = target_data->target_or_pipeline(); @@ -294,7 +295,7 @@ void WatchChangeAggregator::HandleExistenceFilter( int current_size = GetCurrentDocumentCountForTarget(target_id); if (current_size != expected_count) { // Apply bloom filter to identify and mark removed documents. - absl::optional bloom_filter = + std::optional bloom_filter = ParseBloomFilter(existence_filter); BloomFilterApplicationStatus status = bloom_filter.has_value() @@ -339,12 +340,12 @@ void WatchChangeAggregator::HandleExistenceFilter( } } -absl::optional WatchChangeAggregator::ParseBloomFilter( +std::optional WatchChangeAggregator::ParseBloomFilter( const ExistenceFilterWatchChange& existence_filter) { - const absl::optional& bloom_filter_parameters = + const std::optional& bloom_filter_parameters = existence_filter.filter().bloom_filter_parameters(); if (!bloom_filter_parameters.has_value()) { - return absl::nullopt; + return std::nullopt; } util::StatusOr maybe_bloom_filter = @@ -354,13 +355,13 @@ absl::optional WatchChangeAggregator::ParseBloomFilter( if (!maybe_bloom_filter.ok()) { LOG_WARN("Creating BloomFilter failed: %s", maybe_bloom_filter.status().error_message()); - return absl::nullopt; + return std::nullopt; } BloomFilter bloom_filter = std::move(maybe_bloom_filter).ValueOrDie(); if (bloom_filter.bit_count() == 0) { - return absl::nullopt; + return std::nullopt; } return bloom_filter; @@ -393,7 +394,7 @@ int WatchChangeAggregator::FilterRemovedDocuments( if (!bloom_filter.MightContain(document_path)) { RemoveDocumentFromTarget(target_id, key, - /*updatedDocument=*/absl::nullopt); + /*updatedDocument=*/std::nullopt); removalCount++; } } @@ -408,7 +409,7 @@ RemoteEvent WatchChangeAggregator::CreateRemoteEvent( TargetId target_id = entry.first; TargetState& target_state = entry.second; - absl::optional target_data = + std::optional target_data = TargetDataForActiveTarget(target_id); if (target_data) { auto doc_paths = GetDocumentPaths(target_data->target_or_pipeline()); @@ -447,7 +448,7 @@ RemoteEvent WatchChangeAggregator::CreateRemoteEvent( bool is_only_limbo_target = true; for (TargetId target_id : entry.second) { - absl::optional target_data = + std::optional target_data = TargetDataForActiveTarget(target_id); if (target_data && target_data->purpose() != QueryPurpose::LimboResolution) { @@ -496,7 +497,7 @@ void WatchChangeAggregator::AddDocumentToTarget( void WatchChangeAggregator::RemoveDocumentFromTarget( TargetId target_id, const DocumentKey& key, - const absl::optional& updated_document) { + const std::optional& updated_document) { if (!IsActiveTarget(target_id)) { return; } @@ -540,15 +541,15 @@ TargetState& WatchChangeAggregator::EnsureTargetState(TargetId target_id) { } bool WatchChangeAggregator::IsActiveTarget(TargetId target_id) const { - return TargetDataForActiveTarget(target_id) != absl::nullopt; + return TargetDataForActiveTarget(target_id) != std::nullopt; } -absl::optional WatchChangeAggregator::TargetDataForActiveTarget( +std::optional WatchChangeAggregator::TargetDataForActiveTarget( TargetId target_id) const { auto target_state = target_states_.find(target_id); return target_state != target_states_.end() && target_state->second.IsPending() - ? absl::optional{} + ? std::optional{} : target_metadata_provider_->GetTargetDataForTarget(target_id); } @@ -567,7 +568,7 @@ void WatchChangeAggregator::ResetTarget(TargetId target_id) { target_metadata_provider_->GetRemoteKeysForTarget(target_id); for (const DocumentKey& key : existing_keys) { - RemoveDocumentFromTarget(target_id, key, absl::nullopt); + RemoveDocumentFromTarget(target_id, key, std::nullopt); } } diff --git a/Firestore/core/src/remote/serializer.cc b/Firestore/core/src/remote/serializer.cc index 8c63aa42bf4..5c609d1691d 100644 --- a/Firestore/core/src/remote/serializer.cc +++ b/Firestore/core/src/remote/serializer.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -178,10 +179,10 @@ FieldPath InvalidFieldPath() { return FieldPath::EmptyPath(); } -absl::optional NotNoneVersionOrNullOpt( +std::optional NotNoneVersionOrNullOpt( const SnapshotVersion& version) { if (version == SnapshotVersion::None()) { - return absl::nullopt; + return std::nullopt; } else { return version; } @@ -845,13 +846,13 @@ Target Serializer::DecodeStructuredQuery( limit = query.limit.value; } - absl::optional start_at; + std::optional start_at; if (query.start_at.values_count > 0) { bool inclusive = query.start_at.before; start_at = Bound::FromValue(DecodeCursorValue(query.start_at), inclusive); } - absl::optional end_at; + std::optional end_at; if (query.end_at.values_count > 0) { bool inclusive = !query.end_at.before; end_at = Bound::FromValue(DecodeCursorValue(query.end_at), inclusive); @@ -1523,7 +1524,7 @@ std::unique_ptr Serializer::DecodeDocumentRemove( return absl::make_unique(std::vector{}, std::move(removed_target_ids), - std::move(key), absl::nullopt); + std::move(key), std::nullopt); } std::unique_ptr Serializer::DecodeExistenceFilterWatchChange( @@ -1535,7 +1536,7 @@ std::unique_ptr Serializer::DecodeExistenceFilterWatchChange( ExistenceFilter Serializer::DecodeExistenceFilter( const google_firestore_v1_ExistenceFilter& filter) const { if (!filter.has_unchanged_names) { - return {filter.count, absl::nullopt}; + return {filter.count, std::nullopt}; } int32_t hash_count = filter.unchanged_names.hash_count; @@ -1578,7 +1579,7 @@ api::PipelineSnapshot Serializer::DecodePipelineResponse( results.reserve(message->results_count); for (pb_size_t i = 0; i < message->results_count; ++i) { - absl::optional key; + std::optional key; if (message->results[i].name != nullptr) { key = DecodeKey(context, message->results[i].name); } @@ -1598,11 +1599,11 @@ api::PipelineSnapshot Serializer::DecodePipelineResponse( return api::PipelineSnapshot(std::move(results), execution_time); } -absl::optional Serializer::DecodePipelineTarget( +std::optional Serializer::DecodePipelineTarget( util::ReadContext* context, const google_firestore_v1_Target_PipelineQueryTarget& proto) const { if (!context->status().ok()) { - return absl::nullopt; + return std::nullopt; } if (proto.which_pipeline_type != @@ -1610,7 +1611,7 @@ absl::optional Serializer::DecodePipelineTarget( context->Fail( StringFormat("Unknown pipeline_type in PipelineQueryTarget: %d", proto.which_pipeline_type)); - return absl::nullopt; + return std::nullopt; } const auto& pipeline_proto = proto.structured_pipeline.pipeline; @@ -1620,7 +1621,7 @@ absl::optional Serializer::DecodePipelineTarget( for (pb_size_t i = 0; i < pipeline_proto.stages_count; ++i) { auto stage_ptr = DecodeStage(context, pipeline_proto.stages[i]); if (!context->status().ok()) { - return absl::nullopt; + return std::nullopt; } decoded_stages.push_back(std::move(stage_ptr)); } @@ -1776,7 +1777,7 @@ api::Ordering Serializer::DecodeOrdering( } std::shared_ptr decoded_expr = nullptr; - absl::optional decoded_direction; + std::optional decoded_direction; const auto& map_value = proto_value.map_value; for (pb_size_t i = 0; i < map_value.fields_count; ++i) { diff --git a/Firestore/core/src/remote/stream.cc b/Firestore/core/src/remote/stream.cc index 130b440dd9b..fc9ccacf4cc 100644 --- a/Firestore/core/src/remote/stream.cc +++ b/Firestore/core/src/remote/stream.cc @@ -17,6 +17,7 @@ #include "Firestore/core/src/remote/stream.h" #include +#include #include #include "Firestore/core/include/firebase/firestore/firestore_errors.h" @@ -118,8 +119,8 @@ void Stream::RequestCredentials() { int initial_close_count = close_count_; auto done = [weak_this, credentials, initial_close_count]( - const absl::optional>& auth, - const absl::optional& app_check) { + const std::optional>& auth, + const std::optional& app_check) { auto strong_this = weak_this.lock(); if (!strong_this) { return; @@ -156,11 +157,11 @@ void Stream::RequestCredentials() { }; auth_credentials_provider_->GetToken( - [done](const StatusOr& auth) { done(auth, absl::nullopt); }); + [done](const StatusOr& auth) { done(auth, std::nullopt); }); app_check_credentials_provider_->GetToken( [done](const StatusOr& app_check) { - done(absl::nullopt, app_check.ValueOrDie()); // AppCheck never fails + done(std::nullopt, app_check.ValueOrDie()); // AppCheck never fails }); } diff --git a/Firestore/core/src/util/comparison.h b/Firestore/core/src/util/comparison.h index 01092e55c5c..47e298916a7 100644 --- a/Firestore/core/src/util/comparison.h +++ b/Firestore/core/src/util/comparison.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -223,13 +224,13 @@ namespace impl { /** * Checks wither the type T has a `CompareTo` member. */ -template > +template > struct has_compare_to : public std::false_type {}; template struct has_compare_to< T, - absl::void_t().CompareTo(std::declval()))>> + std::void_t().CompareTo(std::declval()))>> : public std::true_type {}; /** diff --git a/Firestore/core/src/util/iterator_adaptors.h b/Firestore/core/src/util/iterator_adaptors.h index 16a022454ce..d34c211eda6 100644 --- a/Firestore/core/src/util/iterator_adaptors.h +++ b/Firestore/core/src/util/iterator_adaptors.h @@ -24,7 +24,6 @@ #include #include "absl/base/port.h" -#include "absl/meta/type_traits.h" namespace firebase { namespace firestore { @@ -419,7 +418,7 @@ struct container_traits { template struct test_size_type : std::false_type {}; template - struct test_size_type> + struct test_size_type> : std::true_type {}; // Conditional provisioning of a size_type which defaults to size_t. diff --git a/Firestore/core/src/util/to_string.h b/Firestore/core/src/util/to_string.h index 9ec456d8339..360a210fed7 100644 --- a/Firestore/core/src/util/to_string.h +++ b/Firestore/core/src/util/to_string.h @@ -104,11 +104,11 @@ namespace impl { // Checks whether the given type `T` defines a member function `ToString` -template > +template > struct has_to_string : std::false_type {}; template -struct has_to_string().ToString())>> +struct has_to_string().ToString())>> : std::true_type {}; template diff --git a/Firestore/core/src/util/type_traits.h b/Firestore/core/src/util/type_traits.h index 131256c1836..5d55bb2c186 100644 --- a/Firestore/core/src/util/type_traits.h +++ b/Firestore/core/src/util/type_traits.h @@ -20,32 +20,30 @@ #include #include -#include "absl/meta/type_traits.h" - namespace firebase { namespace firestore { namespace util { // is_iterable -template > +template > struct is_iterable : std::false_type {}; template struct is_iterable< T, - absl::void_t().begin(), std::declval().end())>> + std::void_t().begin(), std::declval().end())>> : std::true_type {}; // is_associative_container -template > +template > struct is_associative_container : std::false_type {}; template struct is_associative_container< T, - absl::void_t())>> + std::void_t())>> : std::true_type {}; } // namespace util diff --git a/Firestore/core/test/unit/util/iterator_adaptors_test.cc b/Firestore/core/test/unit/util/iterator_adaptors_test.cc index 1b77e515d07..04c5a712e63 100644 --- a/Firestore/core/test/unit/util/iterator_adaptors_test.cc +++ b/Firestore/core/test/unit/util/iterator_adaptors_test.cc @@ -1085,26 +1085,26 @@ TEST_F(IteratorAdaptorTest, ViewTypeParameterConstVsNonConst) { typedef value_view_type::type VVC; // key_view: - KV ABSL_ATTRIBUTE_UNUSED kv1 = key_view(m); // lvalue - KVC ABSL_ATTRIBUTE_UNUSED kv2 = key_view(m); // conversion to const - KVC ABSL_ATTRIBUTE_UNUSED kv3 = key_view(cm); // const from const lvalue - KVC ABSL_ATTRIBUTE_UNUSED kv4 = key_view(M()); // const from rvalue + [[maybe_unused]] KV kv1 = key_view(m); // lvalue + [[maybe_unused]] KVC kv2 = key_view(m); // conversion to const + [[maybe_unused]] KVC kv3 = key_view(cm); // const from const lvalue + [[maybe_unused]] KVC kv4 = key_view(M()); // const from rvalue // Direct initialization (without key_view function) - KV ABSL_ATTRIBUTE_UNUSED kv5(m); - KVC ABSL_ATTRIBUTE_UNUSED kv6(m); - KVC ABSL_ATTRIBUTE_UNUSED kv7(cm); - KVC ABSL_ATTRIBUTE_UNUSED kv8((M())); + [[maybe_unused]] KV kv5(m); + [[maybe_unused]] KVC kv6(m); + [[maybe_unused]] KVC kv7(cm); + [[maybe_unused]] KVC kv8((M())); // value_view: - VV ABSL_ATTRIBUTE_UNUSED vv1 = value_view(m); // lvalue - VVC ABSL_ATTRIBUTE_UNUSED vv2 = value_view(m); // conversion to const - VVC ABSL_ATTRIBUTE_UNUSED vv3 = value_view(cm); // const from const lvalue - VVC ABSL_ATTRIBUTE_UNUSED vv4 = value_view(M()); // const from rvalue + [[maybe_unused]] VV vv1 = value_view(m); // lvalue + [[maybe_unused]] VVC vv2 = value_view(m); // conversion to const + [[maybe_unused]] VVC vv3 = value_view(cm); // const from const lvalue + [[maybe_unused]] VVC vv4 = value_view(M()); // const from rvalue // Direct initialization (without value_view function) - VV ABSL_ATTRIBUTE_UNUSED vv5(m); - VVC ABSL_ATTRIBUTE_UNUSED vv6(m); - VVC ABSL_ATTRIBUTE_UNUSED vv7(cm); - VVC ABSL_ATTRIBUTE_UNUSED vv8((M())); + [[maybe_unused]] VV vv5(m); + [[maybe_unused]] VVC vv6(m); + [[maybe_unused]] VVC vv7(cm); + [[maybe_unused]] VVC vv8((M())); } TEST_F(IteratorAdaptorTest, EmptyAndSize) {