From 0203b06a61637cd8185f363e04ee86c7d1ae0f43 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Thu, 21 Mar 2013 18:44:13 -0400 Subject: [PATCH] Cursor delete operation only requires cursor handle and key (no need for a value) --- c_src/wterl.c | 15 ++++++++++----- src/wterl.erl | 15 ++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/c_src/wterl.c b/c_src/wterl.c index 446e48e..5e75998 100644 --- a/c_src/wterl.c +++ b/c_src/wterl.c @@ -101,7 +101,7 @@ static ErlNifFunc nif_funcs[] = {"cursor_prev", 1, wterl_cursor_prev}, {"cursor_prev_key", 1, wterl_cursor_prev_key}, {"cursor_prev_value", 1, wterl_cursor_prev_value}, - {"cursor_remove", 3, wterl_cursor_remove}, + {"cursor_remove", 2, wterl_cursor_remove}, {"cursor_reset", 1, wterl_cursor_reset}, {"cursor_search", 2, wterl_cursor_search}, {"cursor_search_near", 2, wterl_cursor_search_near}, @@ -614,16 +614,21 @@ static inline ERL_NIF_TERM wterl_cursor_data_op(ErlNifEnv* env, int argc, const { ErlNifBinary key, value; int rc; - if (enif_inspect_binary(env, argv[1], &key) && enif_inspect_binary(env, argv[2], &value)) + + if (enif_inspect_binary(env, argv[1], &key) && + (op == WTERL_OP_CURSOR_REMOVE ? 1 : enif_inspect_binary(env, argv[2], &value))) { WT_CURSOR* cursor = cursor_handle->cursor; WT_ITEM raw_key, raw_value; raw_key.data = key.data; raw_key.size = key.size; cursor->set_key(cursor, &raw_key); - raw_value.data = value.data; - raw_value.size = value.size; - cursor->set_value(cursor, &raw_value); + if (op != WTERL_OP_CURSOR_REMOVE) + { + raw_value.data = value.data; + raw_value.size = value.size; + cursor->set_value(cursor, &raw_value); + } switch (op) { case WTERL_OP_CURSOR_INSERT: diff --git a/src/wterl.erl b/src/wterl.erl index 9c66da3..61ffa89 100644 --- a/src/wterl.erl +++ b/src/wterl.erl @@ -31,7 +31,7 @@ cursor_prev/1, cursor_prev_key/1, cursor_prev_value/1, - cursor_remove/3, + cursor_remove/2, cursor_reset/1, cursor_search/2, cursor_search_near/2, @@ -242,8 +242,8 @@ cursor_insert(_Cursor, _Key, _Value) -> cursor_update(_Cursor, _Key, _Value) -> ?nif_stub. --spec cursor_remove(cursor(), key(), value()) -> ok | {error, term()}. -cursor_remove(_Cursor, _Key, _Value) -> +-spec cursor_remove(cursor(), key()) -> ok | {error, term()}. +cursor_remove(_Cursor, _Key) -> ?nif_stub. -type fold_keys_fun() :: fun((Key::binary(), any()) -> any()). @@ -586,13 +586,10 @@ various_cursor_test_() -> {"remove an item using a cursor", fun() -> {ok, Cursor} = cursor_open(SRef, "table:test"), - ?assertMatch(ok, - cursor_remove(Cursor, <<"g">>, <<"goji berries">>)), - ?assertMatch(not_found, - cursor_remove(Cursor, <<"l">>, <<"lemon">>)), + ?assertMatch(ok, cursor_remove(Cursor, <<"g">>)), + ?assertMatch(not_found, cursor_remove(Cursor, <<"l">>)), ?assertMatch(ok, cursor_close(Cursor)), - ?assertMatch(not_found, - session_get(SRef, "table:test", <<"g">>)) + ?assertMatch(not_found, session_get(SRef, "table:test", <<"g">>)) end}]} end}.