Bug 1168606 - Reduce code duplication for different cursor directions. r=ttung,asuth

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

--HG--
extra : amend_source : 6be8c103a4deec383ac2d4cb22e9ad67f3c74e4d
This commit is contained in:
Simon Giesecke 2019-08-21 09:27:59 +02:00
parent 542ab16b7c
commit 603ae52908

View File

@ -26005,48 +26005,26 @@ nsresult Cursor::OpenOp::DoObjectStoreKeyDatabaseWork(
keyRangeClause.Truncate();
nsAutoCString continueToKeyRangeClause;
const bool isUpperBound = mCursor->mDirection == IDBCursor::NEXT ||
mCursor->mDirection == IDBCursor::NEXT_UNIQUE;
Key bound;
bool open;
GetRangeKeyInfo(!isUpperBound, &bound, &open);
NS_NAMED_LITERAL_CSTRING(currentKey, "current_key");
NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key");
AppendConditionClause(keyString, currentKey, !isUpperBound, false,
keyRangeClause);
AppendConditionClause(keyString, currentKey, !isUpperBound, true,
continueToKeyRangeClause);
if (usingKeyRange && !bound.IsUnset()) {
NS_NAMED_LITERAL_CSTRING(rangeKey, "range_key");
switch (mCursor->mDirection) {
case IDBCursor::NEXT:
case IDBCursor::NEXT_UNIQUE: {
Key upper;
bool open;
GetRangeKeyInfo(false, &upper, &open);
AppendConditionClause(keyString, currentKey, false, false,
keyRangeClause);
AppendConditionClause(keyString, currentKey, false, true,
continueToKeyRangeClause);
if (usingKeyRange && !upper.IsUnset()) {
AppendConditionClause(keyString, rangeKey, true, !open, keyRangeClause);
AppendConditionClause(keyString, rangeKey, true, !open,
continueToKeyRangeClause);
mCursor->mRangeKey = upper;
}
break;
}
case IDBCursor::PREV:
case IDBCursor::PREV_UNIQUE: {
Key lower;
bool open;
GetRangeKeyInfo(true, &lower, &open);
AppendConditionClause(keyString, currentKey, true, false, keyRangeClause);
AppendConditionClause(keyString, currentKey, true, true,
continueToKeyRangeClause);
if (usingKeyRange && !lower.IsUnset()) {
AppendConditionClause(keyString, rangeKey, false, !open,
keyRangeClause);
AppendConditionClause(keyString, rangeKey, false, !open,
continueToKeyRangeClause);
mCursor->mRangeKey = lower;
}
break;
}
default:
MOZ_CRASH("Should never get here!");
AppendConditionClause(keyString, rangeKey, isUpperBound, !open,
keyRangeClause);
AppendConditionClause(keyString, rangeKey, isUpperBound, !open,
continueToKeyRangeClause);
mCursor->mRangeKey = bound;
}
mCursor->mContinueQuery =