Replace enif_alloc_binary/enif_make_binary call pairs with a single

enif_make_new_binary call.
This commit is contained in:
Keith Bostic 2012-02-20 13:30:09 -05:00
parent 6c0f14da6e
commit cddaf8e1d9

View file

@ -405,10 +405,9 @@ static ERL_NIF_TERM wterl_session_get(ErlNifEnv* env, int argc, const ERL_NIF_TE
(void)cursor->close(cursor); (void)cursor->close(cursor);
if (rc == 0) if (rc == 0)
{ {
ErlNifBinary value; ERL_NIF_TERM value;
enif_alloc_binary(raw_value.size, &value); memcpy(enif_make_new_binary(env, raw_value.size, &value), raw_value.data, raw_value.size);
memcpy(value.data, raw_value.data, raw_value.size); return enif_make_tuple2(env, ATOM_OK, value);
return enif_make_tuple2(env, ATOM_OK, enif_make_binary(env, &value));
} }
else else
{ {
@ -513,10 +512,9 @@ static ERL_NIF_TERM wterl_cursor_key_ret(ErlNifEnv* env, WT_CURSOR *cursor, int
rc = cursor->get_key(cursor, &raw_key); rc = cursor->get_key(cursor, &raw_key);
if (rc == 0) if (rc == 0)
{ {
ErlNifBinary key; ERL_NIF_TERM key;
enif_alloc_binary(raw_key.size, &key); memcpy(enif_make_new_binary(env, raw_key.size, &key), raw_key.data, raw_key.size);
memcpy(key.data, raw_key.data, raw_key.size); return enif_make_tuple2(env, ATOM_OK, key);
return enif_make_tuple2(env, ATOM_OK, enif_make_binary(env, &key));
} }
} }
return wterl_strerror(env, rc); return wterl_strerror(env, rc);
@ -533,13 +531,10 @@ static ERL_NIF_TERM wterl_cursor_kv_ret(ErlNifEnv* env, WT_CURSOR *cursor, int r
rc = cursor->get_value(cursor, &raw_value); rc = cursor->get_value(cursor, &raw_value);
if (rc == 0) if (rc == 0)
{ {
ErlNifBinary key, value; ERL_NIF_TERM key, value;
enif_alloc_binary(raw_key.size, &key); memcpy(enif_make_new_binary(env, raw_key.size, &key), raw_key.data, raw_key.size);
memcpy(key.data, raw_key.data, raw_key.size); memcpy(enif_make_new_binary(env, raw_value.size, &value), raw_value.data, raw_value.size);
enif_alloc_binary(raw_value.size, &value); return enif_make_tuple3(env, ATOM_OK, key, value);
memcpy(value.data, raw_value.data, raw_value.size);
return enif_make_tuple3(env, ATOM_OK,
enif_make_binary(env, &key), enif_make_binary(env, &value));
} }
} }
} }
@ -554,10 +549,9 @@ static ERL_NIF_TERM wterl_cursor_value_ret(ErlNifEnv* env, WT_CURSOR *cursor, in
rc = cursor->get_value(cursor, &raw_value); rc = cursor->get_value(cursor, &raw_value);
if (rc == 0) if (rc == 0)
{ {
ErlNifBinary value; ERL_NIF_TERM value;
enif_alloc_binary(raw_value.size, &value); memcpy(enif_make_new_binary(env, raw_value.size, &value), raw_value.data, raw_value.size);
memcpy(value.data, raw_value.data, raw_value.size); return enif_make_tuple2(env, ATOM_OK, value);
return enif_make_tuple2(env, ATOM_OK, enif_make_binary(env, &value));
} }
} }
return wterl_strerror(env, rc); return wterl_strerror(env, rc);