@@ -91,20 +91,26 @@ public void Dispose()
91
91
92
92
public bool FindFirstKey ( in ReadOnlySpan < byte > prefix )
93
93
{
94
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
95
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
94
96
_modifiedFromLastFind = false ;
95
97
_keyIndex = - 1 ;
96
98
return _cursor ! . FindFirst ( prefix ) ;
97
99
}
98
100
99
101
public bool FindLastKey ( in ReadOnlySpan < byte > prefix )
100
102
{
103
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
104
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
101
105
_modifiedFromLastFind = false ;
102
106
_keyIndex = _cursor ! . FindLastWithPrefix ( prefix ) ;
103
107
return _keyIndex >= 0 ;
104
108
}
105
109
106
110
public bool FindPreviousKey ( in ReadOnlySpan < byte > prefix )
107
111
{
112
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
113
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
108
114
if ( _modifiedFromLastFind )
109
115
{
110
116
if ( FindKeyIndex ( _keyIndex - 1 ) && _cursor ! . KeyHasPrefix ( prefix ) )
@@ -132,6 +138,8 @@ public bool FindPreviousKey(in ReadOnlySpan<byte> prefix)
132
138
133
139
public bool FindNextKey ( in ReadOnlySpan < byte > prefix )
134
140
{
141
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
142
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
135
143
if ( _modifiedFromLastFind )
136
144
{
137
145
if ( ! _removedCurrent ) _keyIndex ++ ;
@@ -160,6 +168,8 @@ public bool FindNextKey(in ReadOnlySpan<byte> prefix)
160
168
161
169
public FindResult Find ( in ReadOnlySpan < byte > key , uint prefixLen )
162
170
{
171
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
172
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
163
173
_modifiedFromLastFind = false ;
164
174
var result = _cursor ! . Find ( key ) ;
165
175
_keyIndex = - 1 ;
@@ -203,6 +213,8 @@ public long GetKeyIndex()
203
213
204
214
public bool FindKeyIndex ( in ReadOnlySpan < byte > prefix , long index )
205
215
{
216
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
217
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
206
218
_modifiedFromLastFind = false ;
207
219
if ( ! _cursor ! . FindFirst ( prefix ) )
208
220
{
@@ -225,6 +237,8 @@ public bool FindKeyIndex(in ReadOnlySpan<byte> prefix, long index)
225
237
226
238
public bool FindKeyIndex ( long index )
227
239
{
240
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
241
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
228
242
_modifiedFromLastFind = false ;
229
243
_keyIndex = - 1 ;
230
244
if ( _cursor ! . SeekIndex ( index ) )
@@ -269,16 +283,22 @@ public KeyValuePair<uint, uint> GetStorageSizeOfCurrentKey()
269
283
270
284
public ReadOnlyMemory < byte > GetKeyMemory ( ref Memory < byte > buffer , bool copy = false )
271
285
{
286
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
287
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
272
288
return _cursor ! . GetKeyMemory ( ref buffer , copy ) ;
273
289
}
274
290
275
291
public ReadOnlySpan < byte > GetKeySpan ( scoped ref Span < byte > buffer , bool copy = false )
276
292
{
293
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
294
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
277
295
return _cursor ! . GetKeySpan ( ref buffer , copy ) ;
278
296
}
279
297
280
298
public ReadOnlySpan < byte > GetKeySpan ( Span < byte > buffer , bool copy = false )
281
299
{
300
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
301
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
282
302
return _cursor ! . GetKeySpan ( buffer , copy ) ;
283
303
}
284
304
@@ -291,6 +311,8 @@ public bool IsValueCorrupted()
291
311
292
312
public ReadOnlyMemory < byte > GetValueMemory ( ref Memory < byte > buffer , bool copy = false )
293
313
{
314
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
315
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
294
316
if ( ! IsValid ( ) ) return new ( ) ;
295
317
var trueValue = _cursor ! . GetValue ( ) ;
296
318
var keyValueDB = _transaction ! . KeyValueDB ;
@@ -319,6 +341,8 @@ public ReadOnlyMemory<byte> GetValueMemory(ref Memory<byte> buffer, bool copy =
319
341
320
342
public ReadOnlySpan < byte > GetValueSpan ( scoped ref Span < byte > buffer , bool copy = false )
321
343
{
344
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
345
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
322
346
if ( ! IsValid ( ) ) return new ( ) ;
323
347
var trueValue = _cursor ! . GetValue ( ) ;
324
348
var keyValueDB = _transaction ! . KeyValueDB ;
@@ -360,6 +384,8 @@ void EnsureValidKey()
360
384
361
385
void EnsureValidCursor ( )
362
386
{
387
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
388
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
363
389
if ( ! _cursor ! . IsValid ( ) )
364
390
{
365
391
if ( _modifiedFromLastFind && _keyIndex != - 1 )
@@ -456,6 +482,8 @@ public long EraseUpTo(IKeyValueDBCursor to)
456
482
[ SkipLocalsInit ]
457
483
public bool CreateOrUpdateKeyValue ( in ReadOnlySpan < byte > key , in ReadOnlySpan < byte > value )
458
484
{
485
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
486
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
459
487
var cursor = ( IKeyValueDBCursorInternal ) _transaction ! . FirstCursor ;
460
488
while ( cursor != null )
461
489
{
@@ -491,6 +519,8 @@ public bool CreateOrUpdateKeyValue(in ReadOnlySpan<byte> key, in ReadOnlySpan<by
491
519
492
520
public UpdateKeySuffixResult UpdateKeySuffix ( in ReadOnlySpan < byte > key , uint prefixLen )
493
521
{
522
+ ObjectDisposedException . ThrowIf ( _transaction == null , this ) ;
523
+ ObjectDisposedException . ThrowIf ( _transaction . BTreeRoot == null , _transaction ) ;
494
524
var cursor = ( IKeyValueDBCursorInternal ) _transaction ! . FirstCursor ;
495
525
while ( cursor != null )
496
526
{
0 commit comments