IDBKeyData MemoryObjectStore::lowestKeyWithRecordInRange(const IDBKeyRangeData& keyRangeData) const { if (!m_keyValueStore) return { }; if (keyRangeData.isExactlyOneKey() && m_keyValueStore->contains(keyRangeData.lowerKey)) return keyRangeData.lowerKey; ASSERT(m_orderedKeys); auto lowestInRange = m_orderedKeys->lower_bound(keyRangeData.lowerKey); if (lowestInRange == m_orderedKeys->end()) return { }; if (keyRangeData.lowerOpen && *lowestInRange == keyRangeData.lowerKey) ++lowestInRange; if (lowestInRange == m_orderedKeys->end()) return { }; if (!keyRangeData.upperKey.isNull()) { if (lowestInRange->compare(keyRangeData.upperKey) > 0) return { }; if (keyRangeData.upperOpen && *lowestInRange == keyRangeData.upperKey) return { }; } return *lowestInRange; }
IDBKeyData IndexValueStore::lowestKeyWithRecordInRange(const IDBKeyRangeData& range) const { LOG(IndexedDB, "IndexValueStore::lowestKeyWithRecordInRange - %s", range.loggingString().utf8().data()); if (range.isExactlyOneKey()) return m_records.contains(range.lowerKey) ? range.lowerKey : IDBKeyData(); auto iterator = lowestIteratorInRange(range); if (iterator == m_orderedKeys.end()) return { }; return *iterator; }
void MemoryObjectStore::deleteRange(const IDBKeyRangeData& inputRange) { LOG(IndexedDB, "MemoryObjectStore::deleteRange"); ASSERT(m_writeTransaction); if (inputRange.isExactlyOneKey()) { deleteRecord(inputRange.lowerKey); return; } IDBKeyRangeData range = inputRange; while (true) { auto key = lowestKeyWithRecordInRange(range); if (key.isNull()) break; deleteRecord(key); range.lowerKey = key; range.lowerOpen = true; } }
IDBGetResult MemoryIndex::getResultForKeyRange(IndexedDB::IndexRecordType type, const IDBKeyRangeData& range) const { LOG(IndexedDB, "MemoryIndex::getResultForKeyRange"); if (!m_records) return { }; IDBKeyData keyToLookFor; if (range.isExactlyOneKey()) keyToLookFor = range.lowerKey; else keyToLookFor = m_records->lowestKeyWithRecordInRange(range); if (keyToLookFor.isNull()) return { }; const IDBKeyData* keyValue = m_records->lowestValueForKey(keyToLookFor); if (!keyValue) return { }; return type == IndexedDB::IndexRecordType::Key ? IDBGetResult(*keyValue) : IDBGetResult(m_objectStore.valueForKeyRange(*keyValue)); }