Skip to content

Commit 6dfdf63

Browse files
committed
make make_binary faster
1 parent 6edec07 commit 6dfdf63

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

c_src/sqlite3_nif.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <assert.h>
22
#include <string.h>
3+
#include <stdint.h>
34
#include <stdio.h>
45

56
// Elixir workaround for . in module names
@@ -182,20 +183,12 @@ make_bind_error(ErlNifEnv* env, ERL_NIF_TERM message, ERL_NIF_TERM argument)
182183
}
183184

184185
static ERL_NIF_TERM
185-
make_binary(ErlNifEnv* env, const void* bytes, unsigned int size)
186+
make_binary(ErlNifEnv* env, const char* bytes, size_t size)
186187
{
187-
ErlNifBinary blob;
188-
ERL_NIF_TERM term;
189-
190-
if (!enif_alloc_binary(size, &blob)) {
191-
return make_atom(env, "out_of_memory");
192-
}
193-
194-
memcpy(blob.data, bytes, size);
195-
term = enif_make_binary(env, &blob);
196-
enif_release_binary(&blob);
197-
198-
return term;
188+
ERL_NIF_TERM bin;
189+
uint8_t* data = enif_make_new_binary(env, size, &bin);
190+
memcpy(data, bytes, size);
191+
return bin;
199192
}
200193

201194
/**

0 commit comments

Comments
 (0)