Changeset 209942 in webkit


Ignore:
Timestamp:
Dec 16, 2016 3:03:26 PM (7 years ago)
Author:
beidson@apple.com
Message:

More SQLiteIDBCursor refactoring.
https://bugs.webkit.org/show_bug.cgi?id=165956

Reviewed by Tim Horton.

No new tests (No behavior change).

This is a simple patch that encapsulates the current state of the cursor in one structure
which will allow for storing multiple-such states in the future (to support prefetching).

  • Modules/indexeddb/server/SQLiteIDBCursor.cpp:

(WebCore::IDBServer::SQLiteIDBCursor::currentData):
(WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindStatement):
(WebCore::IDBServer::SQLiteIDBCursor::advance):
(WebCore::IDBServer::SQLiteIDBCursor::advanceUnique):
(WebCore::IDBServer::SQLiteIDBCursor::markAsErrored):
(WebCore::IDBServer::SQLiteIDBCursor::internalAdvanceOnce):
(WebCore::IDBServer::SQLiteIDBCursor::iterate):

  • Modules/indexeddb/server/SQLiteIDBCursor.h:

(WebCore::IDBServer::SQLiteIDBCursor::currentRecordRowID):
(WebCore::IDBServer::SQLiteIDBCursor::currentKey):
(WebCore::IDBServer::SQLiteIDBCursor::currentPrimaryKey):
(WebCore::IDBServer::SQLiteIDBCursor::currentValue):
(WebCore::IDBServer::SQLiteIDBCursor::didComplete):
(WebCore::IDBServer::SQLiteIDBCursor::didError):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r209940 r209942  
     12016-12-16  Brady Eidson  <beidson@apple.com>
     2
     3        More SQLiteIDBCursor refactoring.
     4        https://bugs.webkit.org/show_bug.cgi?id=165956
     5
     6        Reviewed by Tim Horton.
     7
     8        No new tests (No behavior change).
     9       
     10        This is a simple patch that encapsulates the current state of the cursor in one structure
     11        which will allow for storing multiple-such states in the future (to support prefetching).
     12
     13        * Modules/indexeddb/server/SQLiteIDBCursor.cpp:
     14        (WebCore::IDBServer::SQLiteIDBCursor::currentData):
     15        (WebCore::IDBServer::SQLiteIDBCursor::resetAndRebindStatement):
     16        (WebCore::IDBServer::SQLiteIDBCursor::advance):
     17        (WebCore::IDBServer::SQLiteIDBCursor::advanceUnique):
     18        (WebCore::IDBServer::SQLiteIDBCursor::markAsErrored):
     19        (WebCore::IDBServer::SQLiteIDBCursor::internalAdvanceOnce):
     20        (WebCore::IDBServer::SQLiteIDBCursor::iterate):
     21       
     22        * Modules/indexeddb/server/SQLiteIDBCursor.h:
     23        (WebCore::IDBServer::SQLiteIDBCursor::currentRecordRowID):
     24        (WebCore::IDBServer::SQLiteIDBCursor::currentKey):
     25        (WebCore::IDBServer::SQLiteIDBCursor::currentPrimaryKey):
     26        (WebCore::IDBServer::SQLiteIDBCursor::currentValue):
     27        (WebCore::IDBServer::SQLiteIDBCursor::didComplete):
     28        (WebCore::IDBServer::SQLiteIDBCursor::didError):
     29
    1302016-12-16  Jer Noble  <jer.noble@apple.com>
    231
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp

    r209893 r209942  
    102102void SQLiteIDBCursor::currentData(IDBGetResult& result)
    103103{
    104     if (m_completed) {
    105         ASSERT(!m_errored);
     104    if (m_currentRecord.completed) {
     105        ASSERT(!m_currentRecord.errored);
    106106        result = { };
    107107        return;
    108108    }
    109109
    110     result = { m_currentRecord.key, m_currentRecord.primaryKey, m_currentRecord.value ? *m_currentRecord.value : IDBValue() };
     110    result = { m_currentRecord.record.key, m_currentRecord.record.primaryKey, m_currentRecord.record.value ? *m_currentRecord.record.value : IDBValue() };
    111111}
    112112
     
    224224
    225225    // If this cursor never fetched any records, we don't need to reset the statement.
    226     if (m_currentRecord.key.isNull())
     226    if (m_currentRecord.record.key.isNull())
    227227        return;
    228228
     
    231231    // We might also have to change the statement from closed to open so we don't refetch the current key a second time.
    232232    if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) {
    233         m_currentLowerKey = m_currentRecord.key;
     233        m_currentLowerKey = m_currentRecord.record.key;
    234234        if (!m_keyRange.lowerOpen) {
    235235            m_keyRange.lowerOpen = true;
     
    238238        }
    239239    } else {
    240         m_currentUpperKey = m_currentRecord.key;
     240        m_currentUpperKey = m_currentRecord.record.key;
    241241        if (!m_keyRange.upperOpen) {
    242242            m_keyRange.upperOpen = true;
     
    294294    bool isUnique = m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate || m_cursorDirection == IndexedDB::CursorDirection::PrevNoDuplicate;
    295295
    296     if (m_completed) {
     296    if (m_currentRecord.completed) {
    297297        LOG_ERROR("Attempt to advance a completed cursor");
    298298        return false;
     
    308308        }
    309309
    310         if (m_completed)
     310        if (m_currentRecord.completed)
    311311            break;
    312312    }
     
    317317bool SQLiteIDBCursor::advanceUnique()
    318318{
    319     IDBKeyData currentKey = m_currentRecord.key;
    320 
    321     while (!m_completed) {
     319    IDBKeyData currentKey = m_currentRecord.record.key;
     320
     321    while (!m_currentRecord.completed) {
    322322        if (!advanceOnce())
    323323            return false;
    324324
    325325        // If the new current key is different from the old current key, we're done.
    326         if (currentKey.compare(m_currentRecord.key))
     326        if (currentKey.compare(m_currentRecord.record.key))
    327327            return true;
    328328    }
     
    346346void SQLiteIDBCursor::markAsErrored()
    347347{
    348     m_completed = true;
    349     m_errored = true;
    350     m_currentRecordRowID = 0;
     348    m_currentRecord.completed = true;
     349    m_currentRecord.errored = true;
     350    m_currentRecord.rowID = 0;
    351351}
    352352
     
    355355    ASSERT(m_transaction->sqliteTransaction());
    356356    ASSERT(m_statement);
    357     ASSERT(!m_completed);
    358 
    359     m_currentRecord.value = nullptr;
     357    ASSERT(!m_currentRecord.completed);
     358
     359    m_currentRecord.record.value = nullptr;
    360360
    361361    int result = m_statement->step();
    362362    if (result == SQLITE_DONE) {
    363         m_completed = true;
    364 
    365363        // When a cursor reaches its end, that is indicated by having undefined keys/values
    366364        m_currentRecord = { };
    367         m_currentRecordRowID = 0;
     365        m_currentRecord.completed = true;
     366        m_currentRecord.rowID = 0;
    368367
    369368        return AdvanceResult::Success;
     
    376375    }
    377376
    378     m_currentRecordRowID = m_statement->getColumnInt64(0);
    379     ASSERT(m_currentRecordRowID);
     377    m_currentRecord.rowID = m_statement->getColumnInt64(0);
     378    ASSERT(m_currentRecord.rowID);
    380379
    381380    Vector<uint8_t> keyData;
    382381    m_statement->getColumnBlobAsVector(1, keyData);
    383382
    384     if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.key)) {
     383    if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.record.key)) {
    385384        LOG_ERROR("Unable to deserialize key data from database while advancing cursor");
    386385        markAsErrored();
     
    392391    // The primaryKey of an ObjectStore cursor is the same as its key.
    393392    if (m_indexID == IDBIndexInfo::InvalidId) {
    394         m_currentRecord.primaryKey = m_currentRecord.key;
     393        m_currentRecord.record.primaryKey = m_currentRecord.record.key;
    395394
    396395        Vector<String> blobURLs, blobFilePaths;
    397         auto error = m_transaction->backingStore().getBlobRecordsForObjectStoreRecord(m_currentRecordRowID, blobURLs, blobFilePaths);
     396        auto error = m_transaction->backingStore().getBlobRecordsForObjectStoreRecord(m_currentRecord.rowID, blobURLs, blobFilePaths);
    398397        if (!error.isNull()) {
    399398            LOG_ERROR("Unable to fetch blob records from database while advancing cursor");
     
    403402
    404403        if (m_cursorType == IndexedDB::CursorType::KeyAndValue)
    405             m_currentRecord.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData), blobURLs, blobFilePaths);
     404            m_currentRecord.record.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData), blobURLs, blobFilePaths);
    406405    } else {
    407         if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.primaryKey)) {
     406        if (!deserializeIDBKeyData(keyData.data(), keyData.size(), m_currentRecord.record.primaryKey)) {
    408407            LOG_ERROR("Unable to deserialize value data from database while advancing index cursor");
    409408            markAsErrored();
     
    425424        if (result == SQLITE_ROW) {
    426425            objectStoreStatement.getColumnBlobAsVector(0, keyData);
    427             m_currentRecord.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData));
     426            m_currentRecord.record.value = std::make_unique<IDBValue>(ThreadSafeDataBuffer::adoptVector(keyData));
    428427        } else if (result == SQLITE_DONE) {
    429428            // This indicates that the record we're trying to retrieve has been removed from the object store.
     
    452451        return result;
    453452
    454     while (!m_completed) {
     453    while (!m_currentRecord.completed) {
    455454        if (!result)
    456455            return false;
     
    458457        // Search for the next key >= the target if the cursor is a Next cursor, or the next key <= if the cursor is a Previous cursor.
    459458        if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) {
    460             if (m_currentRecord.key.compare(targetKey) >= 0)
     459            if (m_currentRecord.record.key.compare(targetKey) >= 0)
    461460                break;
    462         } else if (m_currentRecord.key.compare(targetKey) <= 0)
     461        } else if (m_currentRecord.record.key.compare(targetKey) <= 0)
    463462            break;
    464463
     
    467466
    468467    if (targetPrimaryKey.isValid()) {
    469         while (!m_completed && !m_currentRecord.key.compare(targetKey)) {
     468        while (!m_currentRecord.completed && !m_currentRecord.record.key.compare(targetKey)) {
    470469            if (!result)
    471470                return false;
     
    473472            // Search for the next primary key >= the primary target if the cursor is a Next cursor, or the next key <= if the cursor is a Previous cursor.
    474473            if (m_cursorDirection == IndexedDB::CursorDirection::Next || m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate) {
    475                 if (m_currentRecord.primaryKey.compare(targetPrimaryKey) >= 0)
     474                if (m_currentRecord.record.primaryKey.compare(targetPrimaryKey) >= 0)
    476475                    break;
    477             } else if (m_currentRecord.primaryKey.compare(targetPrimaryKey) <= 0)
     476            } else if (m_currentRecord.record.primaryKey.compare(targetPrimaryKey) <= 0)
    478477                break;
    479478
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h

    r209893 r209942  
    6161
    6262    int64_t objectStoreID() const { return m_objectStoreID; }
    63     int64_t currentRecordRowID() const { return m_currentRecordRowID; }
     63    int64_t currentRecordRowID() const { return m_currentRecord.rowID; }
    6464
    65     const IDBKeyData& currentKey() const { return m_currentRecord.key; }
    66     const IDBKeyData& currentPrimaryKey() const { return m_currentRecord.primaryKey; }
    67     IDBValue* currentValue() const { return m_currentRecord.value.get(); }
     65    const IDBKeyData& currentKey() const { return m_currentRecord.record.key; }
     66    const IDBKeyData& currentPrimaryKey() const { return m_currentRecord.record.primaryKey; }
     67    IDBValue* currentValue() const { return m_currentRecord.record.value.get(); }
    6868
    6969    bool advance(uint64_t count);
    7070    bool iterate(const IDBKeyData& targetKey, const IDBKeyData& targetPrimaryKey);
    7171
    72     bool didComplete() const { return m_completed; }
    73     bool didError() const { return m_errored; }
     72    bool didComplete() const { return m_currentRecord.completed; }
     73    bool didError() const { return m_currentRecord.errored; }
    7474
    7575    void objectStoreRecordsChanged();
     
    107107    IDBKeyData m_currentUpperKey;
    108108
    109     IDBCursorRecord m_currentRecord;
     109    struct SQLiteCursorRecord {
     110        IDBCursorRecord record;
     111        bool completed { false };
     112        bool errored { false };
     113        int64_t rowID { 0 };
     114    };
     115
     116    SQLiteCursorRecord m_currentRecord;
    110117
    111118    std::unique_ptr<SQLiteStatement> m_statement;
     
    113120    int64_t m_boundID { 0 };
    114121
    115     bool m_completed { false };
    116     bool m_errored { false };
    117 
    118122    bool m_backingStoreCursor { false };
    119     int64_t m_currentRecordRowID { 0 };
    120123};
    121124
Note: See TracChangeset for help on using the changeset viewer.