Skip to content

Commit

Permalink
Avoid 0 byte allocation call when statement takes no parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sodabrew committed Dec 4, 2017
1 parent 973390f commit e9c1e1f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
// Get count of ordinary arguments, and extract hash opts/keyword arguments
c = rb_scan_args(argc, argv, "*:", NULL, &opts);

// Scratch space for string encoding exports, allocate on the stack
params_enc = alloca(sizeof(VALUE) * c);

stmt = stmt_wrapper->stmt;

bind_count = mysql_stmt_param_count(stmt);
Expand All @@ -278,6 +275,8 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {

// setup any bind variables in the query
if (bind_count > 0) {
// Scratch space for string encoding exports, allocate on the stack
params_enc = alloca(sizeof(VALUE) * c);
bind_buffers = xcalloc(bind_count, sizeof(MYSQL_BIND));
length_buffers = xcalloc(bind_count, sizeof(unsigned long));

Expand Down

0 comments on commit e9c1e1f

Please sign in to comment.