Skip to content

Commit 6ae1209

Browse files
authored
ext/pdo: Rearrange struct to pack and group related fields together (#17651)
All bound related fields are now part of the same cache line
1 parent ff80ec7 commit 6ae1209

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

ext/pdo/php_pdo_driver.h

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -560,28 +560,21 @@ struct _pdo_stmt_t {
560560
const struct pdo_stmt_methods *methods;
561561
void *driver_data;
562562

563+
/* the cursor specific error code. */
564+
pdo_error_type error_code;
565+
563566
/* if true, we've already successfully executed this statement at least
564567
* once */
565-
unsigned executed:1;
566-
/* if true, the statement supports placeholders and can implement
567-
* bindParam() for its prepared statements, if false, PDO should
568-
* emulate prepare and bind on its behalf */
569-
unsigned supports_placeholders:2;
568+
uint16_t executed:1;
570569

571570
/* If true we are in a do_fetch() call, and modification to the statement must be prevented */
572-
unsigned in_fetch:1;
573-
unsigned _reserved:28;
571+
uint16_t in_fetch:1;
574572

575-
/* the number of columns in the result set; not valid until after
576-
* the statement has been executed at least once. In some cases, might
577-
* not be valid until fetch (at the driver level) has been called at least once.
578-
* */
579-
int column_count;
580-
struct pdo_column_data *columns;
581-
582-
/* we want to keep the dbh alive while we live, so we own a reference */
583-
zend_object *database_object_handle;
584-
pdo_dbh_t *dbh;
573+
/* if true, the statement supports placeholders and can implement
574+
* bindParam() for its prepared statements, if false, PDO should
575+
* emulate prepare and bind on its behalf */
576+
uint16_t supports_placeholders:2;
577+
uint16_t reserved: 12;
585578

586579
/* keep track of bound input parameters. Some drivers support
587580
* input/output parameters, but you can't rely on that working */
@@ -592,24 +585,16 @@ struct _pdo_stmt_t {
592585
* in the result set */
593586
HashTable *bound_columns;
594587

595-
/* not always meaningful */
596-
zend_long row_count;
597-
598-
/* used to hold the statement's current query */
599-
zend_string *query_string;
600-
601-
/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
602-
zend_string *active_query_string;
603-
604-
/* the cursor specific error code. */
605-
pdo_error_type error_code;
606-
607-
/* for lazy fetches, we always return the same lazy object handle.
608-
* Let's keep it here. */
609-
zval lazy_object_ref;
588+
struct pdo_column_data *columns;
589+
/* the number of columns in the result set; not valid until after
590+
* the statement has been executed at least once. In some cases, might
591+
* not be valid until fetch (at the driver level) has been called at least once.
592+
* */
593+
int32_t column_count;
610594

611595
/* defaults for fetches */
612596
enum pdo_fetch_type default_fetch_type;
597+
613598
union {
614599
int column;
615600
struct {
@@ -622,6 +607,23 @@ struct _pdo_stmt_t {
622607
zend_object *into;
623608
} fetch;
624609

610+
/* for lazy fetches, we always return the same lazy object handle.
611+
* Let's keep it here. */
612+
zval lazy_object_ref;
613+
614+
pdo_dbh_t *dbh;
615+
/* we want to keep the dbh alive while we live, so we own a reference */
616+
zend_object *database_object_handle;
617+
618+
/* not always meaningful */
619+
zend_long row_count;
620+
621+
/* used to hold the statement's current query */
622+
zend_string *query_string;
623+
624+
/* the copy of the query with expanded binds ONLY for emulated-prepare drivers */
625+
zend_string *active_query_string;
626+
625627
/* used by the query parser for driver specific
626628
* parameter naming (see pgsql driver for example) */
627629
const char *named_rewrite_template;
@@ -634,6 +636,8 @@ struct _pdo_stmt_t {
634636
zend_object std;
635637
};
636638

639+
640+
637641
static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
638642
return (pdo_stmt_t *)((char*)(obj) - XtOffsetOf(pdo_stmt_t, std));
639643
}

0 commit comments

Comments
 (0)