com php-src: Reduced memory realocations: ext/date/php_date .c ext/standard/basic_functions.c ext/standard/browsc ap.c ext/standard/dns.c
ext/standard/dns_win32. c
| From: | Dmitry Stogov | Date: | Tue, 15 Apr 2014 18:43:18 +0000 |
| Subject: | com php-src: Reduced memory realocations: ext/date/php_date .c ext/standard/basic_functions.c ext/standard/browsc ap.c ext/standard/dns.c ext/standard/dns_win32. c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77381@lists.php.net to get a copy of this message | ||
Commit: 6cf5e51f3eab233d8694a9b1344eecc62ca0e1c0
Author: Dmitry Stogov <dmitry@zend.com> Tue, 15 Apr 2014 22:43:18 +0400
Parents: d0cc5c633c3eeaa61fe1108e74ba9c5941e580c0
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6cf5e51f3eab233d8694a9b1344eecc62ca0e1c0
Log:
Reduced memory realocations
Changed paths:
M ext/date/php_date.c
M ext/standard/basic_functions.c
M ext/standard/browscap.c
M ext/standard/dns.c
M ext/standard/dns_win32.c
Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 8009897..68084a2 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2204,17 +2204,15 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC) /* {{{
*/
ZVAL_STRING(&zv, dateobj->time->tz_info->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- char *tmpstr = emalloc(sizeof("UTC+05:00"));
+ zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
timelib_sll utc_offset = dateobj->time->z;
- snprintf(tmpstr, sizeof("+05:00"), "%c%02d:%02d",
+ tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
utc_offset > 0 ? '-' : '+',
abs(utc_offset / 60),
abs((utc_offset % 60)));
- // TODO: avoid reallocation ???
- ZVAL_STRING(&zv, tmpstr);
- efree(tmpstr);
+ ZVAL_STR(&zv, tmpstr);
}
break;
case TIMELIB_ZONETYPE_ABBR:
@@ -2299,16 +2297,14 @@ static HashTable *date_object_get_properties_timezone(zval *object
TSRMLS_DC) /*
ZVAL_STRING(&zv, tzobj->tzi.tz->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- char *tmpstr = emalloc(sizeof("UTC+05:00"));
+ zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
- snprintf(tmpstr, sizeof("+05:00"), "%c%02d:%02d",
+ tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
tzobj->tzi.utc_offset > 0 ? '-' : '+',
abs(tzobj->tzi.utc_offset / 60),
abs((tzobj->tzi.utc_offset % 60)));
- // TODO: avoid reallocation ???
- ZVAL_STRING(&zv, tmpstr);
- efree(tmpstr);
+ ZVAL_STR(&zv, tmpstr);
}
break;
case TIMELIB_ZONETYPE_ABBR:
@@ -3736,18 +3732,15 @@ PHP_FUNCTION(timezone_name_get)
RETURN_STRING(tzobj->tzi.tz->name);
break;
case TIMELIB_ZONETYPE_OFFSET: {
- char *tmpstr = emalloc(sizeof("UTC+05:00"));
+ zend_string *tmpstr = STR_ALLOC(sizeof("UTC+05:00")-1, 0);
timelib_sll utc_offset = tzobj->tzi.utc_offset;
- snprintf(tmpstr, sizeof("+05:00"), "%c%02d:%02d",
+ tmpstr->len = snprintf(tmpstr->val, sizeof("+05:00"), "%c%02d:%02d",
utc_offset > 0 ? '-' : '+',
abs(utc_offset / 60),
abs((utc_offset % 60)));
- // TODO: avoid reallocation ???
- RETVAL_STRING(tmpstr);
- efree(tmpstr);
- return;
+ RETURN_STR(tmpstr);
}
break;
case TIMELIB_ZONETYPE_ABBR:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 0dc9874..9d68788 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -3806,7 +3806,6 @@ PHP_RSHUTDOWN_FUNCTION(basic) /* {{{ */
setlocale(LC_CTYPE, "");
zend_update_current_locale();
}
-//??? STR_FREE(BG(locale_string));
if (BG(locale_string)) {
efree(BG(locale_string));
BG(locale_string) = NULL;
diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c
index 08a01d5..ef49ee4 100644
--- a/ext/standard/browscap.c
+++ b/ext/standard/browscap.c
@@ -83,7 +83,6 @@ static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */
zend_string *res;
char *lc_pattern;
- // TODO: overflow check???
res = STR_SAFE_ALLOC(Z_STRLEN_P(pattern), 2, 4, persistent);
t = res->val;
diff --git a/ext/standard/dns.c b/ext/standard/dns..c
index 2501a03..de0e24a 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -506,24 +506,24 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch,
int
{
int ll = 0;
zval entries;
+ zend_string *tp;
add_assoc_string(subarray, "type", "TXT");
- tp = emalloc(dlen + 1);
+ tp = STR_ALLOC(dlen, 0);
array_init(&entries);
while (ll < dlen) {
n = cp[ll];
- memcpy(tp + ll , cp + ll + 1, n);
+ memcpy(tp->val + ll , cp + ll + 1, n);
add_next_index_stringl(&entries, (char*)cp + ll + 1, n);
ll = ll + n + 1;
}
- tp[dlen] = '\0';
+ tp->val[dlen] = '\0';
+ tp->len = dlen;
cp += dlen;
- // TODO: avoid reallocation ???
- add_assoc_stringl(subarray, "txt", (char*)tp, (dlen>0)?dlen - 1:0);
- efree(tp);
+ add_assoc_str(subarray, "txt", tp);
add_assoc_zval(subarray, "entries", &entries);
}
break;
diff --git a/ext/standard/dns_win32.c b/ext/standard/dns_win32.c
index 5fd0da0..4deed0b 100644
--- a/ext/standard/dns_win32.c
+++ b/ext/standard/dns_win32.c
@@ -207,7 +207,8 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int raw,
DWORD i = 0;
DNS_TXT_DATA *data_txt = &pRec->Data.TXT;
DWORD count = data_txt->dwStringCount;
- char *txt, *txt_dst;
+ zend_string *txt;
+ char *txt_dst;
long txt_len = 0;
zval *entries;
@@ -220,18 +221,16 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int
raw,
txt_len += strlen(data_txt->pStringArray[i]) + 1;
}
- txt = ecalloc(txt_len * 2, 1);
- txt_dst = txt;
+ txt = STR_SAFE_ALLOC(txt_len, 2, 0, 0);
+ txt_dst = txt->val;
for (i = 0; i < count; i++) {
int len = strlen(data_txt->pStringArray[i]);
memcpy(txt_dst, data_txt->pStringArray[i], len);
add_next_index_stringl(entries, data_txt->pStringArray[i], len);
txt_dst += len;
}
-
- // TODO: avoid reallocation ???
- add_assoc_string(*subarray, "txt", txt);
- efree(txt);
+ tct->len = txt_dst - txt->val;
+ add_assoc_str(*subarray, "txt", txt);
add_assoc_zval(*subarray, "entries", entries);
}
break;