Skip to content

Commit 7e1a041

Browse files
committed
ext/pdo: Rearrange struct to pack and group related fields together
All bound related fields are now part of the same cache line
1 parent 3ff7758 commit 7e1a041

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

ext/pdo/php_pdo_driver.h

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -560,28 +560,20 @@ 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+
uint8_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+
uint8_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+
uint8_t supports_placeholders:2;
585577

586578
/* keep track of bound input parameters. Some drivers support
587579
* input/output parameters, but you can't rely on that working */
@@ -592,24 +584,16 @@ struct _pdo_stmt_t {
592584
* in the result set */
593585
HashTable *bound_columns;
594586

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;
587+
struct pdo_column_data *columns;
588+
/* the number of columns in the result set; not valid until after
589+
* the statement has been executed at least once. In some cases, might
590+
* not be valid until fetch (at the driver level) has been called at least once.
591+
* */
592+
int32_t column_count;
610593

611594
/* defaults for fetches */
612595
enum pdo_fetch_type default_fetch_type;
596+
613597
union {
614598
int column;
615599
struct {
@@ -622,6 +606,23 @@ struct _pdo_stmt_t {
622606
zend_object *into;
623607
} fetch;
624608

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

638+
639+
637640
static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
638641
return (pdo_stmt_t *)((char*)(obj) - XtOffsetOf(pdo_stmt_t, std));
639642
}

0 commit comments

Comments
 (0)