com php-src: Cleanup: avoid reallocations: ext/soap/php_schem a.c
| From: | Dmitry Stogov | Date: | Wed, 23 Sep 2015 22:35:16 +0000 |
| Subject: | com php-src: Cleanup: avoid reallocations: ext/soap/php_schem a.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89152@lists.php.net to get a copy of this message | ||
Commit: 57575c0898d39ffd4c5d874f9e47c2ecc48e11a2
Author: Dmitry Stogov <dmitry@zend.com> Thu, 24 Sep 2015 01:35:16 +0300
Parents: 5cccd6c5b6288231c4d556174f9ea1207b2e933a
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=57575c0898d39ffd4c5d874f9e47c2ecc48e11a2
Log:
Cleanup: avoid reallocations
Changed paths:
M ext/soap/php_schema.c
Diff:
diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c
index 4e69ecd..76b20e9 100644
--- a/ext/soap/php_schema.c
+++ b/ext/soap/php_schema.c
@@ -457,14 +457,13 @@ static int schema_list(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr listType,
sdlTypeP
memset(newType, 0, sizeof(sdlType));
{
- smart_str anonymous = {0};
+ char buf[MAX_LENGTH_OF_LONG + 1];
+ char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1,
zend_hash_num_elements(sdl->types));
+ char *str = emalloc(sizeof("anonymous") + buf + sizeof(buf) - 1 - res);
- smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
- smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
- smart_str_0(&anonymous);
- // TODO: avoid reallocation ???
- newType->name = estrndup(ZSTR_VAL(anonymous.s), ZSTR_LEN(anonymous.s));
- smart_str_free(&anonymous);
+ memcpy(str, "anonymous", sizeof("anonymous")-1);
+ memcpy(str + sizeof("anonymous")-1, res, buf + sizeof(buf) - res);
+ newType->name = str;
}
newType->namens = estrdup((char*)tns->children->content);
@@ -555,14 +554,13 @@ static int schema_union(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr unionType,
sdlTyp
memset(newType, 0, sizeof(sdlType));
{
- smart_str anonymous = {0};
-
- smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
- smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
- smart_str_0(&anonymous);
- // TODO: avoid reallocation ???
- newType->name = estrndup(ZSTR_VAL(anonymous.s), ZSTR_LEN(anonymous.s));
- smart_str_free(&anonymous);
+ char buf[MAX_LENGTH_OF_LONG + 1];
+ char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1,
zend_hash_num_elements(sdl->types));
+ char *str = emalloc(sizeof("anonymous") + buf + sizeof(buf) - 1 - res);
+
+ memcpy(str, "anonymous", sizeof("anonymous")-1);
+ memcpy(str + sizeof("anonymous")-1, res, buf + sizeof(buf) - res);
+ newType->name = str;
}
newType->namens = estrdup((char*)tns->children->content);
@@ -1928,14 +1926,13 @@ static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType,
sdl
dummy_type = emalloc(sizeof(sdlType));
memset(dummy_type, 0, sizeof(sdlType));
{
- smart_str anonymous = {0};
-
- smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
- smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
- smart_str_0(&anonymous);
- // TODO: avoid reallocation ???
- dummy_type->name = estrndup(ZSTR_VAL(anonymous.s), ZSTR_LEN(anonymous.s));
- smart_str_free(&anonymous);
+ char buf[MAX_LENGTH_OF_LONG + 1];
+ char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1,
zend_hash_num_elements(sdl->types));
+ char *str = emalloc(sizeof("anonymous") + buf + sizeof(buf) - 1 - res);
+
+ memcpy(str, "anonymous", sizeof("anonymous")-1);
+ memcpy(str + sizeof("anonymous")-1, res, buf + sizeof(buf) - res);
+ dummy_type->name = str;
}
dummy_type->namens = estrdup((char*)tns->children->content);
schema_simpleType(sdl, tns, trav, dummy_type);