Skip to content

Commit 012cb59

Browse files
committed
date: Avoid passing objects using double pointers
Using single pointers is cleaner and also generates better machine code.
1 parent 7419b57 commit 012cb59

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

ext/date/php_date.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,7 +4613,7 @@ PHP_METHOD(DateInterval, __construct)
46134613
}
46144614
/* }}} */
46154615

4616-
static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, const HashTable *myht) /* {{{ */
4616+
static void php_date_interval_initialize_from_hash(php_interval_obj *intobj, const HashTable *myht) /* {{{ */
46174617
{
46184618
/* If we have a date_string, use that instead */
46194619
const zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string"));
@@ -4635,15 +4635,15 @@ static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, co
46354635
}
46364636

46374637
/* If ->diff is already set, then we need to free it first */
4638-
if ((*intobj)->diff) {
4639-
timelib_rel_time_dtor((*intobj)->diff);
4638+
if (intobj->diff) {
4639+
timelib_rel_time_dtor(intobj->diff);
46404640
}
46414641

4642-
(*intobj)->diff = timelib_rel_time_clone(&time->relative);
4643-
(*intobj)->initialized = true;
4644-
(*intobj)->civil_or_wall = PHP_DATE_CIVIL;
4645-
(*intobj)->from_string = true;
4646-
(*intobj)->date_string = zend_string_copy(Z_STR_P(date_str));
4642+
intobj->diff = timelib_rel_time_clone(&time->relative);
4643+
intobj->initialized = true;
4644+
intobj->civil_or_wall = PHP_DATE_CIVIL;
4645+
intobj->from_string = true;
4646+
intobj->date_string = zend_string_copy(Z_STR_P(date_str));
46474647

46484648
timelib_time_dtor(time);
46494649
timelib_error_container_dtor(err);
@@ -4652,20 +4652,20 @@ static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, co
46524652
}
46534653

46544654
/* If ->diff is already set, then we need to free it first */
4655-
if ((*intobj)->diff) {
4656-
timelib_rel_time_dtor((*intobj)->diff);
4655+
if (intobj->diff) {
4656+
timelib_rel_time_dtor(intobj->diff);
46574657
}
46584658

46594659
/* Set new value */
4660-
(*intobj)->diff = timelib_rel_time_ctor();
4660+
intobj->diff = timelib_rel_time_ctor();
46614661

46624662
#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype, def) \
46634663
do { \
46644664
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
46654665
if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
4666-
(*intobj)->diff->member = (itype)zval_get_long(z_arg); \
4666+
intobj->diff->member = (itype)zval_get_long(z_arg); \
46674667
} else { \
4668-
(*intobj)->diff->member = (itype)def; \
4668+
intobj->diff->member = (itype)def; \
46694669
} \
46704670
} while (0);
46714671

@@ -4675,35 +4675,35 @@ static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, co
46754675
if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
46764676
zend_string *tmp_str; \
46774677
zend_string *str = zval_get_tmp_string(z_arg, &tmp_str); \
4678-
DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
4678+
DATE_A64I(intobj->diff->member, ZSTR_VAL(str)); \
46794679
zend_tmp_string_release(tmp_str); \
46804680
} else { \
4681-
(*intobj)->diff->member = -1LL; \
4681+
intobj->diff->member = -1LL; \
46824682
} \
46834683
} while (0);
46844684

46854685
#define PHP_DATE_INTERVAL_READ_PROPERTY_DAYS(member) \
46864686
do { \
46874687
zval *z_arg = zend_hash_str_find(myht, "days", sizeof("days") - 1); \
46884688
if (z_arg && Z_TYPE_P(z_arg) == IS_FALSE) { \
4689-
(*intobj)->diff->member = TIMELIB_UNSET; \
4689+
intobj->diff->member = TIMELIB_UNSET; \
46904690
} else if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
46914691
zend_string *tmp_str; \
46924692
zend_string *str = zval_get_tmp_string(z_arg, &tmp_str); \
4693-
DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
4693+
DATE_A64I(intobj->diff->member, ZSTR_VAL(str)); \
46944694
zend_tmp_string_release(tmp_str); \
46954695
} else { \
4696-
(*intobj)->diff->member = -1LL; \
4696+
intobj->diff->member = -1LL; \
46974697
} \
46984698
} while (0);
46994699

47004700
#define PHP_DATE_INTERVAL_READ_PROPERTY_DOUBLE(element, member, def) \
47014701
do { \
47024702
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
47034703
if (z_arg) { \
4704-
(*intobj)->diff->member = (double)zval_get_double(z_arg); \
4704+
intobj->diff->member = (double)zval_get_double(z_arg); \
47054705
} else { \
4706-
(*intobj)->diff->member = (double)def; \
4706+
intobj->diff->member = (double)def; \
47074707
} \
47084708
} while (0);
47094709

@@ -4716,7 +4716,7 @@ static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, co
47164716
{
47174717
const zval *z_arg = zend_hash_str_find(myht, "f", sizeof("f") - 1);
47184718
if (z_arg) {
4719-
(*intobj)->diff->us = zend_dval_to_lval(zval_get_double(z_arg) * 1000000.0);
4719+
intobj->diff->us = zend_dval_to_lval(zval_get_double(z_arg) * 1000000.0);
47204720
}
47214721
}
47224722
PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int, -1)
@@ -4730,14 +4730,14 @@ static void php_date_interval_initialize_from_hash(php_interval_obj **intobj, co
47304730
PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", have_special_relative, unsigned int, 0);
47314731
{
47324732
const zval *z_arg = zend_hash_str_find(myht, "civil_or_wall", sizeof("civil_or_wall") - 1);
4733-
(*intobj)->civil_or_wall = PHP_DATE_CIVIL;
4733+
intobj->civil_or_wall = PHP_DATE_CIVIL;
47344734
if (z_arg) {
47354735
zend_long val = zval_get_long(z_arg);
4736-
(*intobj)->civil_or_wall = val;
4736+
intobj->civil_or_wall = val;
47374737
}
47384738
}
47394739

4740-
(*intobj)->initialized = true;
4740+
intobj->initialized = true;
47414741
} /* }}} */
47424742

47434743
/* {{{ */
@@ -4752,7 +4752,7 @@ PHP_METHOD(DateInterval, __set_state)
47524752

47534753
php_date_instantiate(date_ce_interval, return_value);
47544754
intobj = Z_PHPINTERVAL_P(return_value);
4755-
php_date_interval_initialize_from_hash(&intobj, myht);
4755+
php_date_interval_initialize_from_hash(intobj, myht);
47564756
}
47574757
/* }}} */
47584758

@@ -4823,7 +4823,7 @@ PHP_METHOD(DateInterval, __unserialize)
48234823

48244824
intervalobj = Z_PHPINTERVAL_P(object);
48254825

4826-
php_date_interval_initialize_from_hash(&intervalobj, myht);
4826+
php_date_interval_initialize_from_hash(intervalobj, myht);
48274827
restore_custom_dateinterval_properties(object, myht);
48284828
}
48294829
/* }}} */
@@ -4841,7 +4841,7 @@ PHP_METHOD(DateInterval, __wakeup)
48414841

48424842
myht = Z_OBJPROP_P(object);
48434843

4844-
php_date_interval_initialize_from_hash(&intobj, myht);
4844+
php_date_interval_initialize_from_hash(intobj, myht);
48454845
}
48464846
/* }}} */
48474847

0 commit comments

Comments
 (0)