Skip to content

Commit 8c192c7

Browse files
committed
Accept regex as zend_string in Phar::buildFromDirectory()
No need to copy it...
1 parent 172c298 commit 8c192c7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ext/phar/phar_object.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,13 +1686,14 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
16861686
*/
16871687
PHP_METHOD(Phar, buildFromDirectory)
16881688
{
1689-
char *dir, *error, *regex = NULL;
1690-
size_t dir_len, regex_len = 0;
1689+
char *dir, *error;
1690+
size_t dir_len;
16911691
bool apply_reg = 0;
16921692
zval arg, arg2, iter, iteriter, regexiter;
16931693
struct _phar_t pass;
1694+
zend_string *regex = NULL;
16941695

1695-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &dir, &dir_len, &regex, &regex_len) == FAILURE) {
1696+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|S", &dir, &dir_len, &regex) == FAILURE) {
16961697
RETURN_THROWS();
16971698
}
16981699

@@ -1744,7 +1745,7 @@ PHP_METHOD(Phar, buildFromDirectory)
17441745

17451746
zval_ptr_dtor(&iter);
17461747

1747-
if (regex_len > 0) {
1748+
if (regex && ZSTR_LEN(regex) > 0) {
17481749
apply_reg = 1;
17491750

17501751
if (SUCCESS != object_init_ex(&regexiter, spl_ce_RegexIterator)) {
@@ -1754,11 +1755,9 @@ PHP_METHOD(Phar, buildFromDirectory)
17541755
RETURN_THROWS();
17551756
}
17561757

1757-
ZVAL_STRINGL(&arg2, regex, regex_len);
1758-
1758+
ZVAL_STR(&arg2, regex);
17591759
zend_call_known_instance_method_with_2_params(spl_ce_RegexIterator->constructor,
17601760
Z_OBJ(regexiter), NULL, &iteriter, &arg2);
1761-
zval_ptr_dtor(&arg2);
17621761
}
17631762

17641763
array_init(return_value);

0 commit comments

Comments
 (0)