Skip to content

Commit

Permalink
ext/pdo: Turn lazy_object_ref into a zend_object* from a zval
Browse files Browse the repository at this point in the history
This saves 8 bytes
  • Loading branch information
Girgias committed Feb 2, 2025
1 parent bed3ee9 commit f710e69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,6 @@ PHP_METHOD(PDO, prepare)
/* give it a reference to me */
GC_ADDREF(&dbh_obj->std);
stmt->database_object_handle = &dbh_obj->std;
/* we haven't created a lazy object yet */
ZVAL_UNDEF(&stmt->lazy_object_ref);

if (dbh->methods->preparer(dbh, statement, stmt, options)) {
if (Z_TYPE(ctor_args) == IS_ARRAY) {
Expand Down Expand Up @@ -1225,8 +1223,6 @@ PHP_METHOD(PDO, query)
/* give it a reference to me */
GC_ADDREF(&dbh_obj->std);
stmt->database_object_handle = &dbh_obj->std;
/* we haven't created a lazy object yet */
ZVAL_UNDEF(&stmt->lazy_object_ref);

if (dbh->methods->preparer(dbh, statement, stmt, NULL)) {
PDO_STMT_CLEAR_ERR();
Expand Down
12 changes: 6 additions & 6 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ PDO_API void php_pdo_stmt_set_column_count(pdo_stmt_t *stmt, int new_count)
stmt->column_count = new_count;
}

static void get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */
static void pdo_get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */
{
if (Z_ISUNDEF(stmt->lazy_object_ref)) {
if (stmt->lazy_object_ref == NULL) {
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), pdo_row_ce);
row->stmt = stmt;
zend_object_std_init(&row->std, pdo_row_ce);
ZVAL_OBJ(&stmt->lazy_object_ref, &row->std);
stmt->lazy_object_ref = &row->std;
GC_ADDREF(&stmt->std);
GC_DELREF(&row->std);
}
ZVAL_COPY(return_value, &stmt->lazy_object_ref);
ZVAL_OBJ_COPY(return_value, stmt->lazy_object_ref);
}
/* }}} */

Expand Down Expand Up @@ -685,7 +685,7 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
}

if (how == PDO_FETCH_LAZY) {
get_lazy_object(stmt, return_value);
pdo_get_lazy_object(stmt, return_value);
return true;
}

Expand Down Expand Up @@ -2373,7 +2373,7 @@ static void pdo_row_free_storage(zend_object *std)
{
pdo_row_t *row = php_pdo_row_fetch_object(std);
if (row->stmt) {
ZVAL_UNDEF(&row->stmt->lazy_object_ref);
row->stmt->lazy_object_ref = NULL;
OBJ_RELEASE(&row->stmt->std);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/pdo/php_pdo_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ struct _pdo_stmt_t {

/* for lazy fetches, we always return the same lazy object handle.
* Let's keep it here. */
zval lazy_object_ref;
zend_object *lazy_object_ref;

/* defaults for fetches */
enum pdo_fetch_type default_fetch_type;
Expand Down

0 comments on commit f710e69

Please sign in to comment.