| Index: content/browser/indexed_db/leveldb/leveldb_transaction.h
|
| diff --git a/content/browser/indexed_db/leveldb/leveldb_transaction.h b/content/browser/indexed_db/leveldb/leveldb_transaction.h
|
| index 83b4763edc1dcb1abf0db458d3fa07983c430606..b7b5d64df1ef08c2dba5796342fbe80da548154a 100644
|
| --- a/content/browser/indexed_db/leveldb/leveldb_transaction.h
|
| +++ b/content/browser/indexed_db/leveldb/leveldb_transaction.h
|
| @@ -5,14 +5,13 @@
|
| #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
|
| #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_TRANSACTION_H_
|
|
|
| +#include <map>
|
| #include <set>
|
| #include <string>
|
| -#include <vector>
|
|
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/strings/string_piece.h"
|
| -#include "content/browser/indexed_db/leveldb/avltree.h"
|
| #include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
|
| #include "content/browser/indexed_db/leveldb/leveldb_database.h"
|
| #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
|
| @@ -38,53 +37,33 @@ class CONTENT_EXPORT LevelDBTransaction
|
| virtual ~LevelDBTransaction();
|
| friend class base::RefCounted<LevelDBTransaction>;
|
|
|
| - struct AVLTreeNode {
|
| - AVLTreeNode();
|
| - ~AVLTreeNode();
|
| + struct Record {
|
| + Record();
|
| + ~Record();
|
| std::string key;
|
| std::string value;
|
| bool deleted;
|
| -
|
| - AVLTreeNode* less;
|
| - AVLTreeNode* greater;
|
| - int balance_factor;
|
| - DISALLOW_COPY_AND_ASSIGN(AVLTreeNode);
|
| };
|
|
|
| - struct AVLTreeAbstractor {
|
| - typedef AVLTreeNode* handle;
|
| - typedef size_t size;
|
| - typedef base::StringPiece key;
|
| -
|
| - handle GetLess(handle h) { return h->less; }
|
| - void SetLess(handle h, handle less) { h->less = less; }
|
| - handle GetGreater(handle h) { return h->greater; }
|
| - void SetGreater(handle h, handle greater) { h->greater = greater; }
|
| -
|
| - int GetBalanceFactor(handle h) { return h->balance_factor; }
|
| - void SetBalanceFactor(handle h, int bf) { h->balance_factor = bf; }
|
| -
|
| - int CompareKeyKey(const key& ka, const key& kb) {
|
| - return comparator_->Compare(ka, kb);
|
| - }
|
| - int CompareKeyNode(const key& k, handle h) {
|
| - return CompareKeyKey(k, h->key);
|
| - }
|
| - int CompareNodeNode(handle ha, handle hb) {
|
| - return CompareKeyKey(ha->key, hb->key);
|
| + class Comparator {
|
| + public:
|
| + explicit Comparator(const LevelDBComparator* comparator)
|
| + : comparator_(comparator) {}
|
| + bool operator()(const base::StringPiece& a,
|
| + const base::StringPiece& b) const {
|
| + return comparator_->Compare(a, b) < 0;
|
| }
|
|
|
| - static handle Null() { return 0; }
|
| -
|
| + private:
|
| const LevelDBComparator* comparator_;
|
| };
|
|
|
| - typedef AVLTree<AVLTreeAbstractor> TreeType;
|
| + typedef std::map<base::StringPiece, Record*, Comparator> DataType;
|
|
|
| - class TreeIterator : public LevelDBIterator {
|
| + class DataIterator : public LevelDBIterator {
|
| public:
|
| - static scoped_ptr<TreeIterator> Create(LevelDBTransaction* transaction);
|
| - virtual ~TreeIterator();
|
| + static scoped_ptr<DataIterator> Create(LevelDBTransaction* transaction);
|
| + virtual ~DataIterator();
|
|
|
| virtual bool IsValid() const OVERRIDE;
|
| virtual void SeekToLast() OVERRIDE;
|
| @@ -94,14 +73,11 @@ class CONTENT_EXPORT LevelDBTransaction
|
| virtual base::StringPiece Key() const OVERRIDE;
|
| virtual base::StringPiece Value() const OVERRIDE;
|
| bool IsDeleted() const;
|
| - void Reset();
|
|
|
| private:
|
| - explicit TreeIterator(LevelDBTransaction* transaction);
|
| - mutable TreeType::Iterator iterator_; // Dereferencing this is non-const.
|
| - TreeType* tree_;
|
| - LevelDBTransaction* transaction_;
|
| - std::string key_;
|
| + explicit DataIterator(LevelDBTransaction* transaction);
|
| + DataType* data_;
|
| + DataType::iterator iterator_;
|
| };
|
|
|
| class TransactionIterator : public LevelDBIterator {
|
| @@ -117,20 +93,20 @@ class CONTENT_EXPORT LevelDBTransaction
|
| virtual void Prev() OVERRIDE;
|
| virtual base::StringPiece Key() const OVERRIDE;
|
| virtual base::StringPiece Value() const OVERRIDE;
|
| - void TreeChanged();
|
| + void DataChanged();
|
|
|
| private:
|
| explicit TransactionIterator(scoped_refptr<LevelDBTransaction> transaction);
|
| void HandleConflictsAndDeletes();
|
| void SetCurrentIteratorToSmallestKey();
|
| void SetCurrentIteratorToLargestKey();
|
| - void RefreshTreeIterator() const;
|
| - bool TreeIteratorIsLower() const;
|
| - bool TreeIteratorIsHigher() const;
|
| + void RefreshDataIterator() const;
|
| + bool DataIteratorIsLower() const;
|
| + bool DataIteratorIsHigher() const;
|
|
|
| scoped_refptr<LevelDBTransaction> transaction_;
|
| const LevelDBComparator* comparator_;
|
| - mutable scoped_ptr<TreeIterator> tree_iterator_;
|
| + mutable scoped_ptr<DataIterator> data_iterator_;
|
| scoped_ptr<LevelDBIterator> db_iterator_;
|
| LevelDBIterator* current_;
|
|
|
| @@ -139,19 +115,20 @@ class CONTENT_EXPORT LevelDBTransaction
|
| REVERSE
|
| };
|
| Direction direction_;
|
| - mutable bool tree_changed_;
|
| + mutable bool data_changed_;
|
| };
|
|
|
| void Set(const base::StringPiece& key, std::string* value, bool deleted);
|
| - void ClearTree();
|
| + void Clear();
|
| void RegisterIterator(TransactionIterator* iterator);
|
| void UnregisterIterator(TransactionIterator* iterator);
|
| - void NotifyIteratorsOfTreeChange();
|
| + void NotifyIterators();
|
|
|
| LevelDBDatabase* db_;
|
| const LevelDBSnapshot snapshot_;
|
| const LevelDBComparator* comparator_;
|
| - TreeType tree_;
|
| + Comparator data_comparator_;
|
| + DataType data_;
|
| bool finished_;
|
| std::set<TransactionIterator*> iterators_;
|
| };
|
|
|