Skip to content

Commit b0aa6b9

Browse files
authored
ext/soap: various optimisations
* replace strcat/strncpy with memcpy for pre-allocated buffers. * remove redundant memset before struct copy.
1 parent 46357cb commit b0aa6b9

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

ext/soap/php_http.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,18 +1168,12 @@ int make_http_soap_request(
11681168
char *t = ZSTR_VAL(new_uri->path);
11691169
char *p = strrchr(t, '/');
11701170
if (p) {
1171-
zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_uri->path) + 2, 0);
1172-
strncpy(ZSTR_VAL(s), t, (p - t) + 1);
1173-
ZSTR_VAL(s)[(p - t) + 1] = 0;
1174-
strcat(ZSTR_VAL(s), ZSTR_VAL(new_uri->path));
1171+
zend_string *s = zend_string_concat2(t, (p - t) + 1, ZSTR_VAL(new_uri->path), ZSTR_LEN(new_uri->path));
11751172
zend_string_release_ex(new_uri->path, 0);
11761173
new_uri->path = s;
11771174
}
11781175
} else {
1179-
zend_string *s = zend_string_alloc(ZSTR_LEN(new_uri->path) + 2, 0);
1180-
ZSTR_VAL(s)[0] = '/';
1181-
ZSTR_VAL(s)[1] = 0;
1182-
strcat(ZSTR_VAL(s), ZSTR_VAL(new_uri->path));
1176+
zend_string *s = zend_string_concat2("/", 1, ZSTR_VAL(new_uri->path), ZSTR_LEN(new_uri->path));
11831177
zend_string_release_ex(new_uri->path, 0);
11841178
new_uri->path = s;
11851179
}

ext/soap/php_sdl.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,6 @@ static HashTable* make_persistent_sdl_function_headers(HashTable *headers, HashT
24332433

24342434
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(headers, key, tmp) {
24352435
pheader = malloc(sizeof(sdlSoapBindingFunctionHeader));
2436-
memset(pheader, 0, sizeof(sdlSoapBindingFunctionHeader));
24372436
*pheader = *tmp;
24382437

24392438
if (pheader->name) {
@@ -2497,7 +2496,6 @@ static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *p
24972496

24982497
ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) {
24992498
pparam = malloc(sizeof(sdlParam));
2500-
memset(pparam, 0, sizeof(sdlParam));
25012499
*pparam = *tmp;
25022500

25032501
if (pparam->paramName) {
@@ -2539,7 +2537,6 @@ static HashTable* make_persistent_sdl_function_faults(sdlFunctionPtr func, HashT
25392537

25402538
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(faults, key, tmp) {
25412539
pfault = malloc(sizeof(sdlFault));
2542-
memset(pfault, 0, sizeof(sdlFault));
25432540
*pfault = *tmp;
25442541

25452542
if (pfault->name) {

0 commit comments

Comments
 (0)