summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-16 19:53:05 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-16 19:53:05 +0200
commit942f5b11f2d91c030a4c87d13f8075538c21abc1 (patch)
tree49ee93c6605694b4d744f48611df903177163846 /common/storage_lmdb.cpp
parent8fe4eace598997c3ff4c74aa04f723e8ea444239 (diff)
downloadsink-942f5b11f2d91c030a4c87d13f8075538c21abc1.tar.gz
sink-942f5b11f2d91c030a4c87d13f8075538c21abc1.zip
Simplified code
The while loop is executed at least once, so advanced is always true.
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 9fb2feb..58e3a9a 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -446,25 +446,23 @@ void DataStore::NamedDatabase::findLatest(const QByteArray &k, const std::functi
446 if ((rc = mdb_cursor_get(cursor, &key, &data, op)) == 0) { 446 if ((rc = mdb_cursor_get(cursor, &key, &data, op)) == 0) {
447 // The first lookup will find a key that is equal or greather than our key 447 // The first lookup will find a key that is equal or greather than our key
448 if (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) { 448 if (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) {
449 bool advanced = false; 449 //Read next value until we no longer match
450 while (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) { 450 while (QByteArray::fromRawData((char *)key.mv_data, key.mv_size).startsWith(k)) {
451 advanced = true;
452 MDB_cursor_op nextOp = MDB_NEXT; 451 MDB_cursor_op nextOp = MDB_NEXT;
453 rc = mdb_cursor_get(cursor, &key, &data, nextOp); 452 rc = mdb_cursor_get(cursor, &key, &data, nextOp);
454 if (rc) { 453 if (rc) {
455 break; 454 break;
456 } 455 }
457 } 456 }
458 if (advanced) { 457 //Now read the previous value, and that's the latest one
459 MDB_cursor_op prefOp = MDB_PREV; 458 MDB_cursor_op prefOp = MDB_PREV;
460 // We read past the end above, just take the last value 459 // We read past the end above, just take the last value
461 if (rc == MDB_NOTFOUND) { 460 if (rc == MDB_NOTFOUND) {
462 prefOp = MDB_LAST; 461 prefOp = MDB_LAST;
463 }
464 rc = mdb_cursor_get(cursor, &key, &data, prefOp);
465 foundValue = true;
466 resultHandler(QByteArray::fromRawData((char *)key.mv_data, key.mv_size), QByteArray::fromRawData((char *)data.mv_data, data.mv_size));
467 } 462 }
463 rc = mdb_cursor_get(cursor, &key, &data, prefOp);
464 foundValue = true;
465 resultHandler(QByteArray::fromRawData((char *)key.mv_data, key.mv_size), QByteArray::fromRawData((char *)data.mv_data, data.mv_size));
468 } 466 }
469 } 467 }
470 468