com php-src: MySQLnd: Avoid some reallocations in PS decoder: ext/mysqlnd/mysqlnd_ps_codec.c
| From: | Nikita Popov | Date: | Thu, 17 Dec 2020 13:41:47 +0000 |
| Subject: | com php-src: MySQLnd: Avoid some reallocations in PS decoder: ext/mysqlnd/mysqlnd_ps_codec.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114490@lists.php.net to get a copy of this message | ||
Commit: 1144b85b8275b49b5cad309ee71d121c536e51eb
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 17 Dec 2020 14:41:47 +0100
Parents: 003d9ba125eea8404c6ec11378381d1ba2e9bcd0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1144b85b8275b49b5cad309ee71d121c536e51eb
Log:
MySQLnd: Avoid some reallocations in PS decoder
Changed paths:
M ext/mysqlnd/mysqlnd_ps_codec.c
Diff:
diff --git a/ext/mysqlnd/mysqlnd_ps_codec.c b/ext/mysqlnd/mysqlnd_ps_codec.c
index e942f10faca..4de730777fb 100644
--- a/ext/mysqlnd/mysqlnd_ps_codec.c
+++ b/ext/mysqlnd/mysqlnd_ps_codec.c
@@ -212,8 +212,7 @@ static void
ps_fetch_time(zval * zv, const MYSQLND_FIELD * const field, const unsigned int pack_len, const
zend_uchar ** row)
{
struct st_mysqlnd_time t;
- zend_ulong length; /* First byte encodes the length*/
- char * value;
+ zend_ulong length; /* First byte encodes the length */
DBG_ENTER("ps_fetch_time");
if ((length = php_mysqlnd_net_field_length(row))) {
@@ -241,24 +240,13 @@ ps_fetch_time(zval * zv, const MYSQLND_FIELD * const field, const unsigned int
p
}
if (field->decimals > 0 && field->decimals < 7) {
- length = mnd_sprintf(
- &value,
- 0,
- "%s%02u:%02u:%02u.%0*u",
- (t.neg ? "-" : ""),
- t.hour,
- t.minute,
- t.second,
- field->decimals,
- (uint32_t) (t.second_part / pow(10, 6 - field->decimals))
- );
+ ZVAL_STR(zv, zend_strpprintf(0, "%s%02u:%02u:%02u.%0*u",
+ (t.neg ? "-" : ""), t.hour, t.minute, t.second, field->decimals,
+ (uint32_t) (t.second_part / pow(10, 6 - field->decimals))));
} else {
- length = mnd_sprintf(&value, 0, "%s%02u:%02u:%02u", (t.neg ? "-" :
""), t.hour, t.minute, t.second);
+ ZVAL_STR(zv, zend_strpprintf(0, "%s%02u:%02u:%02u",
+ (t.neg ? "-" : ""), t.hour, t.minute, t.second));
}
-
- DBG_INF_FMT("%s", value);
- ZVAL_STRINGL(zv, value, length);
- mnd_sprintf_free(value);
DBG_VOID_RETURN;
}
/* }}} */
@@ -270,7 +258,6 @@ ps_fetch_date(zval * zv, const MYSQLND_FIELD * const field, const unsigned int p
{
struct st_mysqlnd_time t = {0};
zend_ulong length; /* First byte encodes the length*/
- char * value;
DBG_ENTER("ps_fetch_date");
if ((length = php_mysqlnd_net_field_length(row))) {
@@ -291,11 +278,7 @@ ps_fetch_date(zval * zv, const MYSQLND_FIELD * const field, const unsigned int
p
t.time_type = MYSQLND_TIMESTAMP_DATE;
}
- length = mnd_sprintf(&value, 0, "%04u-%02u-%02u", t.year, t.month, t.day);
-
- DBG_INF_FMT("%s", value);
- ZVAL_STRINGL(zv, value, length);
- mnd_sprintf_free(value);
+ ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u", t.year, t.month, t.day));
DBG_VOID_RETURN;
}
/* }}} */
@@ -307,7 +290,6 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned i
{
struct st_mysqlnd_time t;
zend_ulong length; /* First byte encodes the length*/
- char * value;
DBG_ENTER("ps_fetch_datetime");
if ((length = php_mysqlnd_net_field_length(row))) {
@@ -336,26 +318,13 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned
i
}
if (field->decimals > 0 && field->decimals < 7) {
- length = mnd_sprintf(
- &value,
- 0,
- "%04u-%02u-%02u %02u:%02u:%02u.%0*u",
- t.year,
- t.month,
- t.day,
- t.hour,
- t.minute,
- t.second,
- field->decimals,
- (uint32_t) (t.second_part / pow(10, 6 - field->decimals))
- );
+ ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u %02u:%02u:%02u.%0*u",
+ t.year, t.month, t.day, t.hour, t.minute, t.second, field->decimals,
+ (uint32_t) (t.second_part / pow(10, 6 - field->decimals))));
} else {
- length = mnd_sprintf(&value, 0, "%04u-%02u-%02u %02u:%02u:%02u", t.year,
t.month, t.day, t..hour, t.minute, t.second);
+ ZVAL_STR(zv, zend_strpprintf(0, "%04u-%02u-%02u %02u:%02u:%02u",
+ t.year, t.month, t.day, t.hour, t.minute, t.second));
}
-
- DBG_INF_FMT("%s", value);
- ZVAL_STRINGL(zv, value, length);
- mnd_sprintf_free(value);
DBG_VOID_RETURN;
}
/* }}} */
@@ -365,15 +334,11 @@ ps_fetch_datetime(zval * zv, const MYSQLND_FIELD * const field, const unsigned
i
static void
ps_fetch_string(zval * zv, const MYSQLND_FIELD * const field, const unsigned int pack_len, const
zend_uchar ** row)
{
- /*
- For now just copy, before we make it possible
- to write \0 to the row buffer
- */
const zend_ulong length = php_mysqlnd_net_field_length(row);
DBG_ENTER("ps_fetch_string");
DBG_INF_FMT("len = %lu", length);
DBG_INF("copying from the row buffer");
- ZVAL_STRINGL(zv, (char *)*row, length);
+ ZVAL_STRINGL_FAST(zv, (char *)*row, length);
(*row) += length;
DBG_VOID_RETURN;