Skip to content

Commit e3d9f1f

Browse files
yohgakibukka
authored andcommitted
Simply use ndigit for flag for zend_dtoa mode
1 parent 3aa2aad commit e3d9f1f

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

ext/json/json_encoder.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
104104
{
105105
size_t len;
106106
char num[PHP_JSON_DOUBLE_MAX_LENGTH];
107-
if (JSON_G(precision) == -1) {
108-
php_0cvt(d, 17, '.', 'e', num);
109-
} else {
110-
php_gcvt(d, JSON_G(precision), '.', 'e', num);
111-
}
107+
108+
php_gcvt(d, JSON_G(precision), '.', 'e', num);
112109
len = strlen(num);
113110
if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_JSON_DOUBLE_MAX_LENGTH - 2) {
114111
num[len++] = '.';

ext/standard/var.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,7 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */
471471
}
472472
efree(tmp_str);
473473
*/
474-
if (PG(serialize_precision < 0)) {
475-
php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str);
476-
} else {
477-
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
478-
}
474+
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
479475
smart_str_appends(buf, tmp_str);
480476
break;
481477
case IS_STRING:
@@ -853,11 +849,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
853849
case IS_DOUBLE: {
854850
char tmp_str[2048]; /* Use the same magic number of spprintf.c NUM_BUF_SIZE */
855851
smart_str_appendl(buf, "d:", 2);
856-
if (PG(serialize_precision < 0)) {
857-
php_0cvt(Z_DVAL_P(struc), 17, '.', 'E', tmp_str);
858-
} else {
859-
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
860-
}
852+
php_gcvt(Z_DVAL_P(struc), (int)PG(serialize_precision), '.', 'E', tmp_str);
861853
smart_str_appends(buf, tmp_str);
862854
smart_str_appendc(buf, ';');
863855
return;

main/snprintf.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,15 @@ static inline char *php_fcvt(double value, int ndigit, int *decpt, int *sign) /*
139139
}
140140
/* }}} */
141141

142-
static inline char *_php_cvt(double value, int ndigit, char dec_point, char exponent, char *buf, int mode) /* {{{ */
142+
PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
143143
{
144144
char *digits, *dst, *src;
145145
int i, decpt, sign;
146+
int mode = ndigit > 0 ? 2 : 0;
146147

148+
if (mode == 0) {
149+
ndigit = 17;
150+
}
147151
digits = zend_dtoa(value, mode, ndigit, &decpt, &sign, NULL);
148152
if (decpt == 9999) {
149153
/*
@@ -234,18 +238,6 @@ static inline char *_php_cvt(double value, int ndigit, char dec_point, char expo
234238
}
235239
/* }}} */
236240

237-
PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
238-
{
239-
return _php_cvt(value, ndigit, dec_point, exponent, buf, 2);
240-
}
241-
/* }}} */
242-
243-
PHPAPI char *php_0cvt(double value, int ndigit, char dec_point, char exponent, char *buf) /* {{{ */
244-
{
245-
return _php_cvt(value, ndigit, dec_point, exponent, buf, 0);
246-
}
247-
/* }}} */
248-
249241

250242

251243
/* {{{ Apache license */

0 commit comments

Comments
 (0)