summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-04-15 22:43:18 +0400
committerDmitry Stogov <dmitry@zend.com>2014-04-15 22:43:18 +0400
commit6cf5e51f3eab233d8694a9b1344eecc62ca0e1c0 (patch)
treeb6b8bd09c81ea620b4fa9ecd98eb0e0fa416d955
parentd0cc5c633c3eeaa61fe1108e74ba9c5941e580c0 (diff)
downloadphp-git-6cf5e51f3eab233d8694a9b1344eecc62ca0e1c0.tar.gz
Reduced memory realocations
-rw-r--r--ext/date/php_date.c25
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/browscap.c1
-rw-r--r--ext/standard/dns.c12
-rw-r--r--ext/standard/dns_win32.c13
5 files changed, 21 insertions, 31 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 8009897b9a..68084a2f6f 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 0dc9874f4b..9d6878817e 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 08a01d5dff..ef49ee4d10 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 2501a03170..de0e24a2d7 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 5fd0da0dea..4deed0bf4a 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;