From 69b48f83dfc287a8430cf8e993d0937c5128623f Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Tue, 25 Jul 2017 06:47:58 +0100 Subject: [PATCH] minor loop optimizations, closes #2633 --- ext/mysqli/mysqli.c | 5 +++-- ext/mysqli/mysqli_api.c | 10 ++++++---- win32/sendmail.c | 7 ++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 04f07a5c93e..d26f32d6528 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1156,7 +1156,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend { #if !defined(MYSQLI_USE_MYSQLND) MYSQL_ROW row; - unsigned int i; + unsigned int i, num_fields; MYSQL_FIELD *fields; zend_ulong *field_len; @@ -1170,8 +1170,9 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend array_init(return_value); field_len = mysql_fetch_lengths(result); + num_fields = mysql_num_fields(result); - for (i = 0; i < mysql_num_fields(result); i++) { + for (i = 0; i < num_fields; i++) { if (row[i]) { zval res; diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index ffdcdaf140a..6793fc8065b 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1210,7 +1210,7 @@ PHP_FUNCTION(mysqli_fetch_fields) zval *mysql_result; zval obj; - unsigned int i; + unsigned int i, num_fields; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) { return; @@ -1219,8 +1219,9 @@ PHP_FUNCTION(mysqli_fetch_fields) MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID); array_init(return_value); + num_fields = mysql_num_fields(result); - for (i = 0; i < mysql_num_fields(result); i++) { + for (i = 0; i < num_fields; i++) { const MYSQL_FIELD *field = mysql_fetch_field_direct(result, i); object_init(&obj); @@ -1266,7 +1267,7 @@ PHP_FUNCTION(mysqli_fetch_lengths) { MYSQL_RES *result; zval *mysql_result; - unsigned int i; + unsigned int i, num_fields; zend_ulong *ret; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) { @@ -1280,8 +1281,9 @@ PHP_FUNCTION(mysqli_fetch_lengths) } array_init(return_value); + num_fields = mysql_num_fields(result); - for (i = 0; i < mysql_num_fields(result); i++) { + for (i = 0; i < num_fields; i++) { add_index_long(return_value, i, ret[i]); } } diff --git a/win32/sendmail.c b/win32/sendmail.c index d83663a4752..808fc8f5fd3 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -698,10 +698,15 @@ static int PostHeader(char *RPath, char *Subject, char *mailTo, char *xheaders) size_t i; if (xheaders) { + size_t headers_lc_len; + if (NULL == (headers_lc = estrdup(xheaders))) { return OUT_OF_MEMORY; } - for (i = 0; i < strlen(headers_lc); i++) { + + headers_lc_len = strlen(headers_lc); + + for (i = 0; i < headers_lc_len; i++) { headers_lc[i] = tolower(headers_lc[i]); } }