Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Firestore/core/src/api/collection_reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "Firestore/core/src/api/collection_reference.h"

#include <optional>
#include <utility>

#include "Firestore/core/src/api/document_reference.h"
Expand Down Expand Up @@ -67,10 +68,10 @@ const std::string& CollectionReference::collection_id() const {
return query().path().last_segment();
}

absl::optional<DocumentReference> CollectionReference::parent() const {
std::optional<DocumentReference> 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());
}
Expand Down
12 changes: 6 additions & 6 deletions Firestore/core/src/api/document_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include "Firestore/core/src/api/document_snapshot.h"

#include <optional>
#include <utility>

#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 {
Expand All @@ -44,13 +44,13 @@ DocumentSnapshot DocumentSnapshot::FromNoDocument(
std::shared_ptr<Firestore> 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> firestore,
model::DocumentKey document_key,
absl::optional<Document> document,
std::optional<Document> document,
SnapshotMetadata metadata)
: firestore_{std::move(firestore)},
internal_key_{std::move(document_key)},
Expand All @@ -67,7 +67,7 @@ bool DocumentSnapshot::exists() const {
return internal_document_.has_value();
}

const absl::optional<Document>& DocumentSnapshot::internal_document() const {
const std::optional<Document>& DocumentSnapshot::internal_document() const {
return internal_document_;
}

Expand All @@ -79,10 +79,10 @@ const std::string& DocumentSnapshot::document_id() const {
return internal_key_.path().last_segment();
}

absl::optional<google_firestore_v1_Value> DocumentSnapshot::GetValue(
std::optional<google_firestore_v1_Value> 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) {
Expand Down
5 changes: 3 additions & 2 deletions Firestore/core/src/api/load_bundle_task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Firestore/core/src/api/load_bundle_task.h"

#include <mutex>
#include <optional>
#include <utility>

#include "Firestore/core/src/util/autoid.h"
Expand Down Expand Up @@ -66,15 +67,15 @@ void LoadBundleTask::RemoveObserver(const LoadBundleHandle& handle) {
}

if (last_observer_.has_value() && last_observer_.value().first == handle) {
last_observer_ = absl::nullopt;
last_observer_ = std::nullopt;
}
}

void LoadBundleTask::RemoveAllObservers() {
std::lock_guard<std::mutex> lock(mutex_);

observers_.clear();
last_observer_ = absl::nullopt;
last_observer_ = std::nullopt;
}

void LoadBundleTask::SetSuccess(LoadBundleTaskProgress success_progress) {
Expand Down
13 changes: 7 additions & 6 deletions Firestore/core/src/bundle/bundle_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Firestore/core/src/bundle/bundle_loader.h"

#include <memory>
#include <optional>
#include <unordered_map>

#include "Firestore/core/include/firebase/firestore/firestore_errors.h"
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -90,7 +91,7 @@ Status BundleLoader::AddElementInternal(const BundleElement& element) {
return Status::OK();
}

StatusOr<absl::optional<LoadBundleTaskProgress>> BundleLoader::AddElement(
StatusOr<std::optional<LoadBundleTaskProgress>> BundleLoader::AddElement(
std::unique_ptr<BundleElement> element_ptr, uint64_t byte_size) {
HARD_ASSERT(element_ptr->element_type() != BundleElement::Type::Metadata,
"Unexpected bundle metadata element.");
Expand All @@ -106,17 +107,17 @@ StatusOr<absl::optional<LoadBundleTaskProgress>> 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<DocumentMap> BundleLoader::ApplyChanges() {
if (current_document_ != absl::nullopt) {
if (current_document_ != std::nullopt) {
return StatusOr<DocumentMap>(
Status(Error::kErrorInvalidArgument,
"Bundled documents end with a document metadata "
Expand Down
9 changes: 5 additions & 4 deletions Firestore/core/src/bundle/bundle_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Firestore/core/src/bundle/bundle_reader.h"

#include <algorithm>
#include <optional>

#include "absl/memory/memory.h"
#include "absl/strings/numbers.h"
Expand Down Expand Up @@ -96,22 +97,22 @@ std::unique_ptr<BundleElement> BundleReader::ReadNextElement() {
return result;
}

absl::optional<std::string> BundleReader::ReadLengthPrefix() {
std::optional<std::string> 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) {
Expand Down
15 changes: 8 additions & 7 deletions Firestore/core/src/core/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <algorithm>
#include <memory>
#include <optional>
#include <ostream>

#include "Firestore/core/src/core/bound.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ const std::set<model::FieldPath> Query::InequalityFilterFields() const {
return result;
}

absl::optional<Operator> Query::FindOpInsideFilters(
std::optional<Operator> Query::FindOpInsideFilters(
const std::vector<Operator>& ops) const {
for (const auto& filter : filters_) {
for (const auto& field_filter : filter.GetFlattenedFilters()) {
Expand All @@ -89,7 +90,7 @@ absl::optional<Operator> Query::FindOpInsideFilters(
}
}
}
return absl::nullopt;
return std::nullopt;
}

std::shared_ptr<const std::vector<OrderBy>> Query::CalculateNormalizedOrderBys()
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -316,13 +317,13 @@ Target Query::ToTarget(const std::vector<OrderBy>& 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>{Bound::FromValue(
? std::optional<Bound>{Bound::FromValue(
end_at_->position(), end_at_->inclusive())}
: absl::nullopt;
: std::nullopt;
auto new_end_at = start_at_
? absl::optional<Bound>{Bound::FromValue(
? std::optional<Bound>{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);
Expand Down
24 changes: 13 additions & 11 deletions Firestore/core/src/core/sync_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "Firestore/core/src/core/sync_engine.h"

#include <optional>

#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"
Expand Down Expand Up @@ -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<TargetChange> synthesized_current_change;
std::optional<TargetChange> 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 =
Expand Down Expand Up @@ -248,7 +250,7 @@ void SyncEngine::WriteMutations(std::vector<model::Mutation>&& 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();
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -512,7 +514,7 @@ void SyncEngine::FailOutstandingPendingWriteCallbacks(

void SyncEngine::EmitNewSnapshotsAndNotifyLocalStore(
const DocumentMap& changes,
const absl::optional<RemoteEvent>& maybe_remote_event) {
const std::optional<RemoteEvent>& maybe_remote_event) {
std::vector<ViewSnapshot> new_snapshots;
std::vector<LocalViewChanges> document_changes_in_all_views;

Expand All @@ -530,7 +532,7 @@ void SyncEngine::EmitNewSnapshotsAndNotifyLocalStore(
view_doc_changes);
}

absl::optional<TargetChange> target_changes;
std::optional<TargetChange> target_changes;
bool targetIsPendingReset = false;
if (maybe_remote_event.has_value()) {
const RemoteEvent& remote_event = maybe_remote_event.value();
Expand Down Expand Up @@ -631,7 +633,7 @@ void SyncEngine::RemoveLimboTarget(const DocumentKey& key) {
PumpEnqueuedLimboResolutions();
}

absl::optional<BundleLoader> SyncEngine::ReadIntoLoader(
std::optional<BundleLoader> SyncEngine::ReadIntoLoader(
const bundle::BundleMetadata& metadata,
bundle::BundleReader& reader,
api::LoadBundleTask& result_task) {
Expand All @@ -645,7 +647,7 @@ absl::optional<BundleLoader> 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.
Expand All @@ -661,7 +663,7 @@ absl::optional<BundleLoader> 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()) {
Expand Down Expand Up @@ -705,7 +707,7 @@ void SyncEngine::LoadBundle(std::shared_ptr<bundle::BundleReader> reader,
}

EmitNewSnapshotsAndNotifyLocalStore(changes.ConsumeValueOrDie(),
absl::nullopt);
std::nullopt);

result_task->SetSuccess(SuccessProgress(bundle_metadata));
}
Expand Down
Loading
Loading