diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-09-24 01:35:16 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-09-24 01:35:16 +0300 |
commit | 57575c0898d39ffd4c5d874f9e47c2ecc48e11a2 (patch) | |
tree | cb20913cccb3f019dc539b94ce3a9d51c4a034be /ext/soap/php_schema.c | |
parent | 5cccd6c5b6288231c4d556174f9ea1207b2e933a (diff) | |
download | php-git-57575c0898d39ffd4c5d874f9e47c2ecc48e11a2.tar.gz |
Cleanup: avoid reallocations
Diffstat (limited to 'ext/soap/php_schema.c')
-rw-r--r-- | ext/soap/php_schema.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index 4e69ecd198..76b20e9b01 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); |