You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2022/06/14 10:06:09 UTC
[couchdb-snappy] 18/38: Quick refactor - only init the structs when necessary
This is an automated email from the ASF dual-hosted git repository.
ronny pushed a commit to branch update-snappy
in repository https://gitbox.apache.org/repos/asf/couchdb-snappy.git
commit 73f2014287f00b96b9a4c24b7fcfffc5150216c7
Author: Peter Membrey <pe...@membrey.hk>
AuthorDate: Fri May 16 22:26:43 2014 +0800
Quick refactor - only init the structs when necessary
---
c_src/snappy_nif.cc | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/c_src/snappy_nif.cc b/c_src/snappy_nif.cc
index ee613ee..47665ca 100644
--- a/c_src/snappy_nif.cc
+++ b/c_src/snappy_nif.cc
@@ -138,10 +138,6 @@ ERL_NIF_TERM
snappy_compress_erl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary input;
- ErlNifBinary empty;
-
- // init empty;
- memset(&empty,0,sizeof(ErlNifBinary));
if(!enif_inspect_iolist_as_binary(env, argv[0], &input)) {
return enif_make_badarg(env);
@@ -151,6 +147,9 @@ snappy_compress_erl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
// Snappy will do this in any case, so might as well skip the
// overhead...
if(input.size == 0) {
+ ErlNifBinary empty;
+ // init empty;
+ memset(&empty,0,sizeof(ErlNifBinary));
return make_ok(env, enif_make_binary(env,&empty));
}
@@ -174,9 +173,6 @@ snappy_decompress_erl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
ErlNifBinary ret;
size_t len;
- // init ret;
- memset(&ret,0,sizeof(ErlNifBinary));
-
if(!enif_inspect_iolist_as_binary(env, argv[0], &bin)) {
return enif_make_badarg(env);
}
@@ -186,6 +182,7 @@ snappy_decompress_erl(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
// Snappy library cannot decompress an empty binary - although
// it will unfortunately let you compress one. If an empty binary
// has been passed - send an empty binary back.
+ memset(&ret,0,sizeof(ErlNifBinary));
return make_ok(env, enif_make_binary(env,&ret));
}