Skip to content

Commit 30bc98c

Browse files
committed
ext/ldap: Merge loops together
1 parent d3e65d5 commit 30bc98c

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

ext/ldap/ldap.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,6 @@ PHP_FUNCTION(ldap_explode_dn)
21012101
{
21022102
zend_long with_attrib;
21032103
char *dn, **ldap_value;
2104-
int i, count;
21052104
size_t dn_len;
21062105

21072106
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl", &dn, &dn_len, &with_attrib) != SUCCESS) {
@@ -2113,16 +2112,12 @@ PHP_FUNCTION(ldap_explode_dn)
21132112
RETURN_FALSE;
21142113
}
21152114

2116-
i=0;
2117-
while (ldap_value[i] != NULL) i++;
2118-
count = i;
2119-
21202115
array_init(return_value);
2121-
2122-
add_assoc_long(return_value, "count", count);
2123-
for (i = 0; i<count; i++) {
2116+
int i;
2117+
for (i = 0; ldap_value[i] != NULL; i++) {
21242118
add_index_string(return_value, i, ldap_value[i]);
21252119
}
2120+
add_assoc_long(return_value, "count", i);
21262121

21272122
ldap_memvfree((void **)ldap_value);
21282123
}

ext/ldap/tests/ldap_explode_dn.phpt

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@ echo "Done\n";
3434
?>
3535
--EXPECT--
3636
array(4) {
37-
["count"]=>
38-
int(3)
3937
[0]=>
4038
string(6) "cn=bob"
4139
[1]=>
4240
string(10) "dc=example"
4341
[2]=>
4442
string(6) "dc=com"
43+
["count"]=>
44+
int(3)
4545
}
4646
array(5) {
47-
["count"]=>
48-
int(4)
4947
[0]=>
5048
string(6) "cn=bob"
5149
[1]=>
@@ -54,20 +52,20 @@ array(5) {
5452
string(10) "dc=example"
5553
[3]=>
5654
string(6) "dc=com"
55+
["count"]=>
56+
int(4)
5757
}
5858
array(4) {
59-
["count"]=>
60-
int(3)
6159
[0]=>
6260
string(3) "bob"
6361
[1]=>
6462
string(7) "example"
6563
[2]=>
6664
string(3) "com"
65+
["count"]=>
66+
int(3)
6767
}
6868
array(5) {
69-
["count"]=>
70-
int(4)
7169
[0]=>
7270
string(3) "bob"
7371
[1]=>
@@ -76,6 +74,8 @@ array(5) {
7674
string(7) "example"
7775
[3]=>
7876
string(3) "com"
77+
["count"]=>
78+
int(4)
7979
}
8080
bool(false)
8181
bool(false)

0 commit comments

Comments
 (0)