Use some early returns in spl_directory

This commit is contained in:
Nikita Popov 2021-07-06 12:00:53 +02:00
parent a3abcc063e
commit 1a81251dbb

View file

@ -1900,13 +1900,13 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent) /
static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, int escape, zval *return_value) /* {{{ */
{
int ret = SUCCESS;
do {
ret = spl_filesystem_file_read(intern, 1);
} while (ret == SUCCESS && !intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
int ret = spl_filesystem_file_read(intern, 1);
if (ret != SUCCESS) {
return ret;
}
} while (!intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
if (ret == SUCCESS) {
size_t buf_len = intern->u.file.current_line_len;
char *buf = estrndup(intern->u.file.current_line, buf_len);
@ -1919,8 +1919,7 @@ static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char deli
if (return_value) {
ZVAL_COPY(return_value, &intern->u.file.current_zval);
}
}
return ret;
return SUCCESS;
}
/* }}} */
@ -2300,12 +2299,13 @@ PHP_METHOD(SplFileObject, fgetcsv)
char *delim = NULL, *enclo = NULL, *esc = NULL;
size_t d_len = 0, e_len = 0, esc_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) {
RETURN_THROWS();
}
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
switch(ZEND_NUM_ARGS())
{
switch (ZEND_NUM_ARGS()) {
case 3:
if (esc_len > 1) {
zend_argument_value_error(3, "must be empty or a single character");
@ -2336,7 +2336,6 @@ PHP_METHOD(SplFileObject, fgetcsv)
}
spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value);
}
}
/* }}} */
/* {{{ Output a field array as a CSV line */