Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf23de09

Browse files
committed
#269 Initial iterator performance enhancements and testing.
1 parenta7a41f4 commitf23de09

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

‎src/main/java/org/lmdbjava/LmdbIterable.java‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88

99
publicclassLmdbIterable<T>implementsIterable<KeyVal<T>>,AutoCloseable {
1010

11+
privatefinalTxn<T>txn;
1112
privatefinalCursor<T>cursor;
12-
privatefinalIterator<KeyVal<T>>iterator;
13+
privatefinalComparator<T>comparator;
14+
privatefinalKeyRange<T>keyRange;
15+
privatebooleaniteratorReturned;
1316

14-
privateLmdbIterable(finalCursor<T>cursor,finalIterator<KeyVal<T>>iterator) {
17+
privateLmdbIterable(
18+
finalTxn<T>txn,
19+
finalCursor<T>cursor,
20+
finalComparator<T>comparator,
21+
finalKeyRange<T>keyRange) {
22+
this.txn =txn;
1523
this.cursor =cursor;
16-
this.iterator =iterator;
24+
this.comparator =comparator;
25+
this.keyRange =keyRange;
1726
}
1827

1928
static <T>voiditerate(finalTxn<T>txn,finalDbi<T>dbi,finalEntryConsumer<T>consumer) {
@@ -51,8 +60,7 @@ static <T> LmdbIterable<T> create(
5160
finalKeyRange<T>keyRange) {
5261
finalCursor<T>cursor =dbi.openCursor(txn);
5362
try {
54-
finalLmdbIterator<T>iterator =createIterator(cursor,txn.proxy,comparator,keyRange);
55-
returnnewLmdbIterable<>(cursor,iterator);
63+
returnnewLmdbIterable<>(txn,cursor,comparator,keyRange);
5664
}catch (finalError |RuntimeExceptione) {
5765
cursor.close();
5866
throwe;
@@ -103,7 +111,11 @@ private static <T> LmdbIterator<T> createIterator(
103111

104112
@Override
105113
publicIterator<KeyVal<T>>iterator() {
106-
returniterator;
114+
if (iteratorReturned) {
115+
thrownewIllegalStateException("Iterator can only be returned once");
116+
}
117+
iteratorReturned =true;
118+
returncreateIterator(cursor,txn.proxy,comparator,keyRange);
107119
}
108120

109121
@Override

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp