Skip to content

Commit 231f21f

Browse files
committed
put span
1 parent 310b0ab commit 231f21f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

RocksDbSharp/Native.Wrap.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ public void rocksdb_put(
4444
if (errptr != IntPtr.Zero)
4545
throw new RocksDbException(errptr);
4646
}
47+
48+
public unsafe void rocksdb_put(
49+
IntPtr db,
50+
IntPtr writeOptions,
51+
byte* key,
52+
long keyLength,
53+
byte* value,
54+
long valueLength,
55+
ColumnFamilyHandle cf)
56+
{
57+
IntPtr errptr;
58+
UIntPtr sklength = (UIntPtr)keyLength;
59+
UIntPtr svlength = (UIntPtr)valueLength;
60+
if (cf == null)
61+
rocksdb_put(db, writeOptions, key, sklength, value, svlength, out errptr);
62+
else
63+
rocksdb_put_cf(db, writeOptions, cf.Handle, key, sklength, value, svlength, out errptr);
64+
if (errptr != IntPtr.Zero)
65+
throw new RocksDbException(errptr);
66+
}
4767

4868

4969
public string rocksdb_get(

RocksDbSharp/RocksDb.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,24 @@ public void Put(byte[] key, byte[] value, ColumnFamilyHandle cf = null, WriteOpt
225225
{
226226
Put(key, key.GetLongLength(0), value, value.GetLongLength(0), cf, writeOptions);
227227
}
228+
229+
public void Put(Span<byte> key, Span<byte> value, ColumnFamilyHandle cf = null, WriteOptions writeOptions = null)
230+
{
231+
Put(key, key.Length, value, value.Length, cf, writeOptions);
232+
}
228233

229234
public void Put(byte[] key, long keyLength, byte[] value, long valueLength, ColumnFamilyHandle cf = null, WriteOptions writeOptions = null)
230235
{
231236
Native.Instance.rocksdb_put(Handle, (writeOptions ?? DefaultWriteOptions).Handle, key, keyLength, value, valueLength, cf);
232237
}
238+
239+
public unsafe void Put(Span<byte> key, long keyLength, Span<byte> value, long valueLength, ColumnFamilyHandle cf = null, WriteOptions writeOptions = null)
240+
{
241+
fixed (byte* keyPtr = &MemoryMarshal.GetReference(key), valuePtr = &MemoryMarshal.GetReference(value))
242+
{
243+
Native.Instance.rocksdb_put(Handle, (writeOptions ?? DefaultWriteOptions).Handle, keyPtr, keyLength, valuePtr, valueLength, cf);
244+
}
245+
}
233246

234247
public Iterator NewIterator(ColumnFamilyHandle cf = null, ReadOptions readOptions = null)
235248
{

0 commit comments

Comments
 (0)