Commit 698d2294 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 1597211 - Use InitializedOnce to reduce statefulness of Cursor class....

Bug 1597211 - Use InitializedOnce to reduce statefulness of Cursor class. r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D53951

--HG--
extra : moz-landing-system : lando
parent 2b070294
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "IndexedDatabase.h" #include "IndexedDatabase.h"
#include "IndexedDatabaseInlines.h" #include "IndexedDatabaseInlines.h"
#include "IndexedDatabaseManager.h" #include "IndexedDatabaseManager.h"
#include "InitializedOnce.h"
#include "js/StructuredClone.h" #include "js/StructuredClone.h"
#include "js/Value.h" #include "js/Value.h"
#include "jsapi.h" #include "jsapi.h"
...@@ -7612,35 +7613,41 @@ class Cursor final : public PBackgroundIDBCursorParent { ...@@ -7612,35 +7613,41 @@ class Cursor final : public PBackgroundIDBCursorParent {
const RefPtr<TransactionBase> mTransaction; const RefPtr<TransactionBase> mTransaction;
const RefPtr<Database> mDatabase; const RefPtr<Database> mDatabase;
const RefPtr<FileManager> mFileManager; const RefPtr<FileManager> mFileManager;
PBackgroundParent* mBackgroundParent;
   
// These should only be touched on the PBackground thread to check whether the struct ActorDependentInfo {
// objectStore or index has been deleted. Holding these saves a hash lookup PBackgroundParent* mBackgroundParent;
// for every call to continue()/advance().
RefPtr<FullObjectStoreMetadata> mObjectStoreMetadata; // These should only be touched on the PBackground thread to check whether
RefPtr<FullIndexMetadata> mIndexMetadata; // the objectStore or index has been deleted. Holding these saves a hash
// lookup for every call to continue()/advance().
RefPtr<FullObjectStoreMetadata> mObjectStoreMetadata;
RefPtr<FullIndexMetadata> mIndexMetadata;
};
InitializedOnce<const ActorDependentInfo> mActorDependentInfo;
   
const int64_t mObjectStoreId; const int64_t mObjectStoreId;
const int64_t mIndexId; const int64_t mIndexId;
   
// TODO: mContinueQuery, mContinueToQuery, mContinuePrimaryKeyQuery and struct ContinueQueries {
// mLocaleAwareRangeBound are initialized by OpenOp, and only read by nsCString mContinueQuery;
// ContinueOp. For ContinueOp, they should only be visible as const. nsCString mContinueToQuery;
nsCString mContinuePrimaryKeyQuery;
nsCString mContinueQuery; };
nsCString mContinueToQuery;
nsCString mContinuePrimaryKeyQuery;
const nsCString
mLocale; ///< The locale if the cursor is locale-aware, otherwise empty.
///< Note that only index-based cursors can be locale-aware.
   
Key mLocaleAwareRangeBound; ///< If the cursor is based on a key range, the InitializedOnce<const ContinueQueries, LazyInit::Allow> mContinueQueries;
InitializedOnce<const Key, LazyInit::Allow>
mLocaleAwareRangeBound; ///< If the cursor is based on a key range, the
///< bound in the direction of iteration (e.g. ///< bound in the direction of iteration (e.g.
///< the upper bound in case of mDirection == ///< the upper bound in case of mDirection ==
///< NEXT). If the cursor is based on a key, it ///< NEXT). If the cursor is based on a key, it
///< is unset. If mLocale is set, this was ///< is unset. If mLocale is set, this was
///< converted to mLocale. ///< converted to mLocale.
   
const nsCString
mLocale; ///< The locale if the cursor is locale-aware, otherwise empty.
///< Note that only index-based cursors can be locale-aware.
CursorOpBase* mCurrentlyRunningOp; CursorOpBase* mCurrentlyRunningOp;
   
const Type mType; const Type mType;
...@@ -7650,7 +7657,6 @@ class Cursor final : public PBackgroundIDBCursorParent { ...@@ -7650,7 +7657,6 @@ class Cursor final : public PBackgroundIDBCursorParent {
   
const bool mUniqueIndex; const bool mUniqueIndex;
const bool mIsSameProcessActor; const bool mIsSameProcessActor;
bool mActorDestroyed;
   
struct ConstructFromTransactionBase {}; struct ConstructFromTransactionBase {};
   
...@@ -7666,7 +7672,7 @@ class Cursor final : public PBackgroundIDBCursorParent { ...@@ -7666,7 +7672,7 @@ class Cursor final : public PBackgroundIDBCursorParent {
   
private: private:
// Reference counted. // Reference counted.
~Cursor() override { MOZ_ASSERT(mActorDestroyed); } ~Cursor() override { MOZ_ASSERT(!mActorDependentInfo); }
   
bool VerifyRequestParams(const CursorRequestParams& aParams, bool VerifyRequestParams(const CursorRequestParams& aParams,
const CursorPosition& aPosition) const; const CursorPosition& aPosition) const;
...@@ -15263,35 +15269,40 @@ Cursor::Cursor(RefPtr<TransactionBase> aTransaction, const Type aType, ...@@ -15263,35 +15269,40 @@ Cursor::Cursor(RefPtr<TransactionBase> aTransaction, const Type aType,
: mTransaction(std::move(aTransaction)), : mTransaction(std::move(aTransaction)),
mDatabase(!IsKeyCursor(aType) ? mTransaction->GetDatabase() : nullptr), mDatabase(!IsKeyCursor(aType) ? mTransaction->GetDatabase() : nullptr),
mFileManager(!IsKeyCursor(aType) ? mDatabase->GetFileManager() : nullptr), mFileManager(!IsKeyCursor(aType) ? mDatabase->GetFileManager() : nullptr),
mBackgroundParent( mActorDependentInfo(
!IsKeyCursor(aType) ? mTransaction->GetBackgroundParent() : nullptr), !IsKeyCursor(aType) ? mTransaction->GetBackgroundParent() : nullptr,
mObjectStoreMetadata(std::move(aObjectStoreMetadata)), std::move(aObjectStoreMetadata), std::move(aIndexMetadata)),
mIndexMetadata(std::move(aIndexMetadata)), mObjectStoreId(
mObjectStoreId(mObjectStoreMetadata->mCommonMetadata.id()), mActorDependentInfo->mObjectStoreMetadata->mCommonMetadata.id()),
mIndexId(mIndexMetadata ? mIndexMetadata->mCommonMetadata.id() : 0), mIndexId(mActorDependentInfo->mIndexMetadata
mLocale(mIndexMetadata ? mIndexMetadata->mCommonMetadata.locale() ? mActorDependentInfo->mIndexMetadata->mCommonMetadata.id()
: EmptyCString()), : 0),
mLocale(
mActorDependentInfo->mIndexMetadata
? mActorDependentInfo->mIndexMetadata->mCommonMetadata.locale()
: EmptyCString()),
mCurrentlyRunningOp(nullptr), mCurrentlyRunningOp(nullptr),
mType(aType), mType(aType),
mDirection(aDirection), mDirection(aDirection),
mMaxExtraCount(IndexedDatabaseManager::MaxPreloadExtraRecords()), mMaxExtraCount(IndexedDatabaseManager::MaxPreloadExtraRecords()),
mUniqueIndex(mIndexMetadata ? mIndexMetadata->mCommonMetadata.unique() mUniqueIndex(
: false), mActorDependentInfo->mIndexMetadata
? mActorDependentInfo->mIndexMetadata->mCommonMetadata.unique()
: false),
mIsSameProcessActor(!BackgroundParent::IsOtherProcessActor( mIsSameProcessActor(!BackgroundParent::IsOtherProcessActor(
mTransaction->GetBackgroundParent())), mTransaction->GetBackgroundParent())) {
mActorDestroyed(false) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(mTransaction); MOZ_ASSERT(mTransaction);
MOZ_ASSERT(mType != OpenCursorParams::T__None); MOZ_ASSERT(mType != OpenCursorParams::T__None);
MOZ_ASSERT(mObjectStoreMetadata); MOZ_ASSERT(mActorDependentInfo->mObjectStoreMetadata);
MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams || MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams ||
mType == OpenCursorParams::TIndexOpenKeyCursorParams, mType == OpenCursorParams::TIndexOpenKeyCursorParams,
mIndexMetadata); mActorDependentInfo->mIndexMetadata);
   
if (!IsKeyCursor(aType)) { if (!IsKeyCursor(aType)) {
MOZ_ASSERT(mDatabase); MOZ_ASSERT(mDatabase);
MOZ_ASSERT(mFileManager); MOZ_ASSERT(mFileManager);
MOZ_ASSERT(mBackgroundParent); MOZ_ASSERT(mActorDependentInfo->mBackgroundParent);
} }
   
static_assert( static_assert(
...@@ -15303,19 +15314,20 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams, ...@@ -15303,19 +15314,20 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams,
const CursorPosition& aPosition) const { const CursorPosition& aPosition) const {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None); MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None);
MOZ_ASSERT(mObjectStoreMetadata); MOZ_ASSERT(mActorDependentInfo->mObjectStoreMetadata);
MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams || MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams ||
mType == OpenCursorParams::TIndexOpenKeyCursorParams, mType == OpenCursorParams::TIndexOpenKeyCursorParams,
mIndexMetadata); mActorDependentInfo->mIndexMetadata);
   
#ifdef DEBUG #ifdef DEBUG
{ {
const RefPtr<FullObjectStoreMetadata> objectStoreMetadata = const RefPtr<FullObjectStoreMetadata> objectStoreMetadata =
mTransaction->GetMetadataForObjectStoreId(mObjectStoreId); mTransaction->GetMetadataForObjectStoreId(mObjectStoreId);
if (objectStoreMetadata) { if (objectStoreMetadata) {
MOZ_ASSERT(objectStoreMetadata == mObjectStoreMetadata); MOZ_ASSERT(objectStoreMetadata ==
mActorDependentInfo->mObjectStoreMetadata);
} else { } else {
MOZ_ASSERT(mObjectStoreMetadata->mDeleted); MOZ_ASSERT(mActorDependentInfo->mObjectStoreMetadata->mDeleted);
} }
   
if (objectStoreMetadata && if (objectStoreMetadata &&
...@@ -15324,16 +15336,17 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams, ...@@ -15324,16 +15336,17 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams,
const RefPtr<FullIndexMetadata> indexMetadata = const RefPtr<FullIndexMetadata> indexMetadata =
mTransaction->GetMetadataForIndexId(objectStoreMetadata, mIndexId); mTransaction->GetMetadataForIndexId(objectStoreMetadata, mIndexId);
if (indexMetadata) { if (indexMetadata) {
MOZ_ASSERT(indexMetadata == mIndexMetadata); MOZ_ASSERT(indexMetadata == mActorDependentInfo->mIndexMetadata);
} else { } else {
MOZ_ASSERT(mIndexMetadata->mDeleted); MOZ_ASSERT(mActorDependentInfo->mIndexMetadata->mDeleted);
} }
} }
} }
#endif #endif
   
if (NS_WARN_IF(mObjectStoreMetadata->mDeleted) || if (NS_WARN_IF(mActorDependentInfo->mObjectStoreMetadata->mDeleted) ||
(mIndexMetadata && NS_WARN_IF(mIndexMetadata->mDeleted))) { (mActorDependentInfo->mIndexMetadata &&
NS_WARN_IF(mActorDependentInfo->mIndexMetadata->mDeleted))) {
ASSERT_UNLESS_FUZZING(); ASSERT_UNLESS_FUZZING();
return false; return false;
} }
...@@ -15416,7 +15429,7 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams, ...@@ -15416,7 +15429,7 @@ bool Cursor::VerifyRequestParams(const CursorRequestParams& aParams,
bool Cursor::Start(const OpenCursorParams& aParams) { bool Cursor::Start(const OpenCursorParams& aParams) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() == mType); MOZ_ASSERT(aParams.type() == mType);
MOZ_ASSERT(!mActorDestroyed); MOZ_ASSERT(mActorDependentInfo);
   
if (NS_WARN_IF(mCurrentlyRunningOp)) { if (NS_WARN_IF(mCurrentlyRunningOp)) {
ASSERT_UNLESS_FUZZING(); ASSERT_UNLESS_FUZZING();
...@@ -15456,7 +15469,7 @@ void Cursor::SendResponseInternal( ...@@ -15456,7 +15469,7 @@ void Cursor::SendResponseInternal(
CursorResponse::TArrayOfObjectStoreKeyCursorResponse || CursorResponse::TArrayOfObjectStoreKeyCursorResponse ||
aResponse.type() == CursorResponse::TArrayOfIndexKeyCursorResponse, aResponse.type() == CursorResponse::TArrayOfIndexKeyCursorResponse,
aFiles.IsEmpty()); aFiles.IsEmpty());
MOZ_ASSERT(!mActorDestroyed); MOZ_ASSERT(mActorDependentInfo);
MOZ_ASSERT(mCurrentlyRunningOp); MOZ_ASSERT(mCurrentlyRunningOp);
   
for (size_t i = 0; i < aFiles.Length(); ++i) { for (size_t i = 0; i < aFiles.Length(); ++i) {
...@@ -15467,11 +15480,11 @@ void Cursor::SendResponseInternal( ...@@ -15467,11 +15480,11 @@ void Cursor::SendResponseInternal(
aResponse.type() == aResponse.type() ==
CursorResponse::TArrayOfIndexCursorResponse); CursorResponse::TArrayOfIndexCursorResponse);
MOZ_ASSERT(mDatabase); MOZ_ASSERT(mDatabase);
MOZ_ASSERT(mBackgroundParent); MOZ_ASSERT(mActorDependentInfo->mBackgroundParent);
   
auto res = auto res = SerializeStructuredCloneFiles(
SerializeStructuredCloneFiles(mBackgroundParent, mDatabase, files, mActorDependentInfo->mBackgroundParent, mDatabase, files,
/* aForPreprocess */ false); /* aForPreprocess */ false);
if (NS_WARN_IF(res.isErr())) { if (NS_WARN_IF(res.isErr())) {
aResponse = ClampResultCode(res.inspectErr()); aResponse = ClampResultCode(res.inspectErr());
break; break;
...@@ -15515,23 +15528,18 @@ void Cursor::SendResponseInternal( ...@@ -15515,23 +15528,18 @@ void Cursor::SendResponseInternal(
   
void Cursor::ActorDestroy(ActorDestroyReason aWhy) { void Cursor::ActorDestroy(ActorDestroyReason aWhy) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(!mActorDestroyed); MOZ_ASSERT(mActorDependentInfo);
mActorDestroyed = true;
   
if (mCurrentlyRunningOp) { if (mCurrentlyRunningOp) {
mCurrentlyRunningOp->NoteActorDestroyed(); mCurrentlyRunningOp->NoteActorDestroyed();
} }
   
mBackgroundParent = nullptr; mActorDependentInfo.reset();
mObjectStoreMetadata = nullptr;
mIndexMetadata = nullptr;
} }
   
mozilla::ipc::IPCResult Cursor::RecvDeleteMe() { mozilla::ipc::IPCResult Cursor::RecvDeleteMe() {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(!mActorDestroyed); MOZ_ASSERT(mActorDependentInfo);
   
if (NS_WARN_IF(mCurrentlyRunningOp)) { if (NS_WARN_IF(mCurrentlyRunningOp)) {
ASSERT_UNLESS_FUZZING(); ASSERT_UNLESS_FUZZING();
...@@ -15550,11 +15558,11 @@ mozilla::ipc::IPCResult Cursor::RecvContinue( ...@@ -15550,11 +15558,11 @@ mozilla::ipc::IPCResult Cursor::RecvContinue(
const Key& aCurrentObjectStoreKey) { const Key& aCurrentObjectStoreKey) {
AssertIsOnBackgroundThread(); AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None); MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None);
MOZ_ASSERT(!mActorDestroyed); MOZ_ASSERT(mActorDependentInfo);
MOZ_ASSERT(mObjectStoreMetadata); MOZ_ASSERT(mActorDependentInfo->mObjectStoreMetadata);
MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams || MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams ||
mType == OpenCursorParams::TIndexOpenKeyCursorParams, mType == OpenCursorParams::TIndexOpenKeyCursorParams,
mIndexMetadata); mActorDependentInfo->mIndexMetadata);
   
const bool trustParams = const bool trustParams =
#ifdef DEBUG #ifdef DEBUG
...@@ -26101,9 +26109,10 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses( ...@@ -26101,9 +26109,10 @@ nsresult Cursor::CursorOpBase::PopulateExtraResponses(
   
void Cursor::SetOptionalKeyRange( void Cursor::SetOptionalKeyRange(
const Maybe<SerializedKeyRange>& aOptionalKeyRange, bool* const aOpen) { const Maybe<SerializedKeyRange>& aOptionalKeyRange, bool* const aOpen) {
MOZ_ASSERT(mLocaleAwareRangeBound.IsUnset());
MOZ_ASSERT(aOpen); MOZ_ASSERT(aOpen);
   
Key localeAwareRangeBound;
if (aOptionalKeyRange.isSome()) { if (aOptionalKeyRange.isSome()) {
const SerializedKeyRange& range = aOptionalKeyRange.ref(); const SerializedKeyRange& range = aOptionalKeyRange.ref();
   
...@@ -26115,7 +26124,7 @@ void Cursor::SetOptionalKeyRange( ...@@ -26115,7 +26124,7 @@ void Cursor::SetOptionalKeyRange(
(range.isOnly() || lowerBound) ? range.lower() : range.upper(); (range.isOnly() || lowerBound) ? range.lower() : range.upper();
if (IsLocaleAware()) { if (IsLocaleAware()) {
ErrorResult rv; ErrorResult rv;
Unused << bound.ToLocaleAwareKey(mLocaleAwareRangeBound, mLocale, rv); Unused << bound.ToLocaleAwareKey(localeAwareRangeBound, mLocale, rv);
   
// XXX Explain why the error is ignored here (If it's impossible, then we // XXX Explain why the error is ignored here (If it's impossible, then we
// should change this to an assertion.) // should change this to an assertion.)
...@@ -26123,11 +26132,13 @@ void Cursor::SetOptionalKeyRange( ...@@ -26123,11 +26132,13 @@ void Cursor::SetOptionalKeyRange(
rv.SuppressException(); rv.SuppressException();
} }
} else { } else {
mLocaleAwareRangeBound = bound; localeAwareRangeBound = bound;
} }
} else { } else {
*aOpen = false; *aOpen = false;
} }
mLocaleAwareRangeBound.init(std::move(localeAwareRangeBound));
} }
   
void Cursor::OpenOp::PrepareKeyConditionClauses( void Cursor::OpenOp::PrepareKeyConditionClauses(
...@@ -26146,9 +26157,8 @@ void Cursor::OpenOp::PrepareKeyConditionClauses( ...@@ -26146,9 +26157,8 @@ void Cursor::OpenOp::PrepareKeyConditionClauses(
bool open; bool open;
mCursor->SetOptionalKeyRange(mOptionalKeyRange, &open); mCursor->SetOptionalKeyRange(mOptionalKeyRange, &open);
   
// TODO: The first condition is probably redundant.
if (mOptionalKeyRange.isSome() && if (mOptionalKeyRange.isSome() &&
!mCursor->mLocaleAwareRangeBound.IsUnset()) { !mCursor->mLocaleAwareRangeBound->IsUnset()) {
AppendConditionClause(aKeyString, kStmtParamNameRangeBound, AppendConditionClause(aKeyString, kStmtParamNameRangeBound,
isIncreasingOrder, !open, keyRangeClause); isIncreasingOrder, !open, keyRangeClause);
AppendConditionClause(aKeyString, kStmtParamNameRangeBound, AppendConditionClause(aKeyString, kStmtParamNameRangeBound,
...@@ -26158,9 +26168,10 @@ void Cursor::OpenOp::PrepareKeyConditionClauses( ...@@ -26158,9 +26168,10 @@ void Cursor::OpenOp::PrepareKeyConditionClauses(
   
const nsAutoCString suffix = aDirectionClause + kOpenLimit + const nsAutoCString suffix = aDirectionClause + kOpenLimit +
NS_LITERAL_CSTRING(":") + kStmtParamNameLimit; NS_LITERAL_CSTRING(":") + kStmtParamNameLimit;
mCursor->mContinueQuery = aQueryStart + keyRangeClause + suffix;
   
mCursor->mContinueToQuery = aQueryStart + continueToKeyRangeClause + suffix; mCursor->mContinueQueries.init(
aQueryStart + keyRangeClause + suffix,
aQueryStart + continueToKeyRangeClause + suffix);
} }
   
void Cursor::OpenOp::PrepareIndexKeyConditionClause( void Cursor::OpenOp::PrepareIndexKeyConditionClause(
...@@ -26172,13 +26183,15 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause( ...@@ -26172,13 +26183,15 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause(
bool open; bool open;
mCursor->SetOptionalKeyRange(mOptionalKeyRange, &open); mCursor->SetOptionalKeyRange(mOptionalKeyRange, &open);
if (mOptionalKeyRange.isSome() && if (mOptionalKeyRange.isSome() &&
!mCursor->mLocaleAwareRangeBound.IsUnset()) { !mCursor->mLocaleAwareRangeBound->IsUnset()) {
AppendConditionClause(aSortColumn, kStmtParamNameRangeBound, AppendConditionClause(aSortColumn, kStmtParamNameRangeBound,
isIncreasingOrder, !open, aQueryStart); isIncreasingOrder, !open, aQueryStart);
} }
} }
   
mCursor->mContinueToQuery = nsCString continueQuery, continueToQuery, continuePrimaryKeyQuery;
continueToQuery =
aQueryStart + NS_LITERAL_CSTRING(" AND ") + aQueryStart + NS_LITERAL_CSTRING(" AND ") +
GetSortKeyClause(isIncreasingOrder ? ComparisonOperator::GreaterOrEquals GetSortKeyClause(isIncreasingOrder ? ComparisonOperator::GreaterOrEquals
: ComparisonOperator::LessOrEquals, : ComparisonOperator::LessOrEquals,
...@@ -26187,7 +26200,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause( ...@@ -26187,7 +26200,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause(
switch (mCursor->mDirection) { switch (mCursor->mDirection) {
case IDBCursor::NEXT: case IDBCursor::NEXT:
case IDBCursor::PREV: case IDBCursor::PREV:
mCursor->mContinueQuery = continueQuery =
aQueryStart + NS_LITERAL_CSTRING(" AND ") + aQueryStart + NS_LITERAL_CSTRING(" AND ") +
GetSortKeyClause(isIncreasingOrder GetSortKeyClause(isIncreasingOrder
? ComparisonOperator::GreaterOrEquals ? ComparisonOperator::GreaterOrEquals
...@@ -26205,7 +26218,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause( ...@@ -26205,7 +26218,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause(
kStmtParamNameObjectStorePosition) + kStmtParamNameObjectStorePosition) +
NS_LITERAL_CSTRING(" ) "); NS_LITERAL_CSTRING(" ) ");
   
mCursor->mContinuePrimaryKeyQuery = continuePrimaryKeyQuery =
aQueryStart + aQueryStart +
NS_LITERAL_CSTRING( NS_LITERAL_CSTRING(
" AND (" " AND ("
...@@ -26227,7 +26240,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause( ...@@ -26227,7 +26240,7 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause(
   
case IDBCursor::NEXT_UNIQUE: case IDBCursor::NEXT_UNIQUE:
case IDBCursor::PREV_UNIQUE: case IDBCursor::PREV_UNIQUE:
mCursor->mContinueQuery = continueQuery =
aQueryStart + NS_LITERAL_CSTRING(" AND ") + aQueryStart + NS_LITERAL_CSTRING(" AND ") +
GetSortKeyClause(isIncreasingOrder ? ComparisonOperator::GreaterThan GetSortKeyClause(isIncreasingOrder ? ComparisonOperator::GreaterThan
: ComparisonOperator::LessThan, : ComparisonOperator::LessThan,
...@@ -26240,11 +26253,15 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause( ...@@ -26240,11 +26253,15 @@ void Cursor::OpenOp::PrepareIndexKeyConditionClause(
   
const nsAutoCString suffix = aDirectionClause + kOpenLimit + const nsAutoCString suffix = aDirectionClause + kOpenLimit +
NS_LITERAL_CSTRING(":") + kStmtParamNameLimit; NS_LITERAL_CSTRING(":") + kStmtParamNameLimit;
mCursor->mContinueQuery += suffix; continueQuery += suffix;
mCursor->mContinueToQuery += suffix; continueToQuery += suffix;
if (!mCursor->mContinuePrimaryKeyQuery.IsEmpty()) { if (!continuePrimaryKeyQuery.IsEmpty()) {
mCursor->mContinuePrimaryKeyQuery += suffix; continuePrimaryKeyQuery += suffix;
} }
mCursor->mContinueQueries.init(std::move(continueQuery),
std::move(continueToQuery),
std::move(continuePrimaryKeyQuery));
} }
   
nsresult Cursor::OpenOp::ProcessStatementSteps( nsresult Cursor::OpenOp::ProcessStatementSteps(
...@@ -26588,9 +26605,7 @@ nsresult Cursor::OpenOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26588,9 +26605,7 @@ nsresult Cursor::OpenOp::DoDatabaseWork(DatabaseConnection* aConnection) {
MOZ_ASSERT(aConnection); MOZ_ASSERT(aConnection);
aConnection->AssertIsOnConnectionThread(); aConnection->AssertIsOnConnectionThread();
MOZ_ASSERT(mCursor); MOZ_ASSERT(mCursor);
MOZ_ASSERT(mCursor->mContinueQuery.IsEmpty()); MOZ_ASSERT(!mCursor->mContinueQueries);
MOZ_ASSERT(mCursor->mContinueToQuery.IsEmpty());
MOZ_ASSERT(mCursor->mContinuePrimaryKeyQuery.IsEmpty());
   
AUTO_PROFILER_LABEL("Cursor::OpenOp::DoDatabaseWork", DOM); AUTO_PROFILER_LABEL("Cursor::OpenOp::DoDatabaseWork", DOM);
   
...@@ -26647,8 +26662,8 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26647,8 +26662,8 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) {
aConnection->AssertIsOnConnectionThread(); aConnection->AssertIsOnConnectionThread();
MOZ_ASSERT(mCursor); MOZ_ASSERT(mCursor);
MOZ_ASSERT(mCursor->mObjectStoreId); MOZ_ASSERT(mCursor->mObjectStoreId);
MOZ_ASSERT(!mCursor->mContinueQuery.IsEmpty()); MOZ_ASSERT(!mCursor->mContinueQueries->mContinueQuery.IsEmpty());
MOZ_ASSERT(!mCursor->mContinueToQuery.IsEmpty()); MOZ_ASSERT(!mCursor->mContinueQueries->mContinueToQuery.IsEmpty());
MOZ_ASSERT(!mCurrentPosition.mPosition.IsUnset()); MOZ_ASSERT(!mCurrentPosition.mPosition.IsUnset());
   
const bool isIndex = const bool isIndex =
...@@ -26657,7 +26672,7 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26657,7 +26672,7 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) {
   
MOZ_ASSERT_IF(isIndex && (mCursor->mDirection == IDBCursor::NEXT || MOZ_ASSERT_IF(isIndex && (mCursor->mDirection == IDBCursor::NEXT ||
mCursor->mDirection == IDBCursor::PREV), mCursor->mDirection == IDBCursor::PREV),
!mCursor->mContinuePrimaryKeyQuery.IsEmpty()); !mCursor->mContinueQueries->mContinuePrimaryKeyQuery.IsEmpty());
MOZ_ASSERT_IF(isIndex, mCursor->mIndexId); MOZ_ASSERT_IF(isIndex, mCursor->mIndexId);
MOZ_ASSERT_IF(isIndex, !mCurrentPosition.mObjectStorePosition.IsUnset()); MOZ_ASSERT_IF(isIndex, !mCurrentPosition.mObjectStorePosition.IsUnset());
   
...@@ -26711,9 +26726,10 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26711,9 +26726,10 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) {
} }
   
const nsCString& continueQuery = const nsCString& continueQuery =
hasContinuePrimaryKey ? mCursor->mContinuePrimaryKeyQuery hasContinuePrimaryKey
: hasContinueKey ? mCursor->mContinueToQuery ? mCursor->mContinueQueries->mContinuePrimaryKeyQuery
: mCursor->mContinueQuery; : hasContinueKey ? mCursor->mContinueQueries->mContinueToQuery
: mCursor->mContinueQueries->mContinueQuery;
   
// TODO: Whether it makes sense to preload depends on the kind of the // TODO: Whether it makes sense to preload depends on the kind of the
// subsequent operations, not of the current operation. We could assume that // subsequent operations, not of the current operation. We could assume that
...@@ -26764,8 +26780,8 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) { ...@@ -26764,8 +26780,8 @@ nsresult Cursor::ContinueOp::DoDatabaseWork(DatabaseConnection* aConnection) {
} }
   
// Bind range bound if it is specified. // Bind range bound if it is specified.
if (!mCursor->mLocaleAwareRangeBound.IsUnset()) { if (!mCursor->mLocaleAwareRangeBound->IsUnset()) {
rv = mCursor->mLocaleAwareRangeBound.BindToStatement( rv = mCursor->mLocaleAwareRangeBound->BindToStatement(
&*stmt, kStmtParamNameRangeBound); &*stmt, kStmtParamNameRangeBound);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment