]> granicus.if.org Git - php/commitdiff
- Simplify
authorMarcus Boerger <helly@php.net>
Sun, 4 Mar 2007 12:02:16 +0000 (12:02 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 4 Mar 2007 12:02:16 +0000 (12:02 +0000)
ext/spl/spl_directory.c
ext/spl/spl_iterators.c

index f57537f08a4bd9a4f694ab33f9cf346a236f6147..494248e44eb2114666dbd3f0874e4e11e309c512 100755 (executable)
@@ -508,6 +508,18 @@ static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_fil
        return NULL;
 } /* }}} */
 
+static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
+{
+       return !strcmp(d_name, ".") || !strcmp(d_name, "..");
+}
+/* }}} */
+
+static int spl_filesystem_is_invalid_or_dot(const char * d_name) /* {{{ */
+{
+       return d_name[0] == '\0' || spl_filesystem_is_dot(d_name);
+}
+/* }}} */
+
 static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{{ */
 {
        spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(obj TSRMLS_CC);
@@ -1149,7 +1161,7 @@ SPL_METHOD(RecursiveDirectoryIterator, rewind)
        }
        do {
                spl_filesystem_dir_read(intern TSRMLS_CC);
-       } while (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, ".."));
+       } while (spl_filesystem_is_dot(intern->u.dir.entry.d_name));
 }
 /* }}} */
 
@@ -1162,7 +1174,7 @@ SPL_METHOD(RecursiveDirectoryIterator, next)
        intern->u.dir.index++;
        do {
                spl_filesystem_dir_read(intern TSRMLS_CC);
-       } while (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, ".."));
+       } while (spl_filesystem_is_dot(intern->u.dir.entry.d_name));
        if (intern->file_name.v) {
                efree(intern->file_name.v);
                intern->file_name = NULL_ZSTR;
@@ -1177,7 +1189,7 @@ SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
        zend_bool allow_links = 0;
        spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
        
-       if (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, "..")) {
+       if (spl_filesystem_is_invalid_or_dot(intern->u.dir.entry.d_name)) {
                RETURN_FALSE;
        } else {
                if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &allow_links) == FAILURE) {
@@ -1443,7 +1455,7 @@ static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter TSRML
        object->u.dir.index++;
        do {
                spl_filesystem_dir_read(object TSRMLS_CC);
-       } while (!strcmp(object->u.dir.entry.d_name, ".") || !strcmp(object->u.dir.entry.d_name, ".."));
+       } while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
        if (object->file_name.v) {
                efree(object->file_name.v);
                object->file_name = NULL_ZSTR;
@@ -1467,7 +1479,7 @@ static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC)
        }
        do {
                spl_filesystem_dir_read(object TSRMLS_CC);
-       } while (!strcmp(object->u.dir.entry.d_name, ".") || !strcmp(object->u.dir.entry.d_name, ".."));
+       } while (spl_filesystem_is_dot(object->u.dir.entry.d_name));
        if (iterator->current) {
                zval_ptr_dtor(&iterator->current);
                iterator->current = NULL;
index 9585eb279bb67724d543fc6e1a79965eec4afc92..5395304fa1fa6bc63def18aebf6f62f33388e43e 100755 (executable)
@@ -1349,41 +1349,6 @@ SPL_METHOD(ParentIterator, __construct)
        spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_ParentIterator, spl_ce_RecursiveIterator, DIT_ParentIterator);
 } /* }}} */
 
-/* {{{ proto bool ParentIterator::hasChildren() U
-   Check whether the inner iterator's current element has children */
-SPL_METHOD(ParentIterator, hasChildren)
-{
-       spl_dual_it_object   *intern;
-       zval                 *retval;
-
-       intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
-       zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "haschildren", &retval);
-       if (retval) {
-               RETURN_ZVAL(retval, 0, 1);
-       } else {
-               RETURN_FALSE;
-       }
-} /* }}} */
-
-/* {{{ proto ParentIterator ParentIterator::getChildren() U
-   Return the inner iterator's children contained in a ParentIterator */
-SPL_METHOD(ParentIterator, getChildren)
-{
-       spl_dual_it_object   *intern;
-       zval                 *retval;
-
-       intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
-       zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
-       if (!EG(exception) && retval) {
-               spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, retval TSRMLS_CC);
-       }
-       if (retval) {
-               zval_ptr_dtor(&retval);
-       }
-} /* }}} */
-
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
 /* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int mode [, int flags [, int preg_flags]]]) U
    Create an RegexIterator from another iterator and a regular expression */
@@ -1700,10 +1665,7 @@ static zend_function_entry spl_funcs_RecursiveFilterIterator[] = {
 
 static zend_function_entry spl_funcs_ParentIterator[] = {
        SPL_ME(ParentIterator,  __construct,      arginfo_parent_it___construct, ZEND_ACC_PUBLIC)
-       SPL_MA(ParentIterator,  accept,           ParentIterator, hasChildren, NULL, ZEND_ACC_PUBLIC)
-       SPL_ME(ParentIterator,  hasChildren,      NULL, ZEND_ACC_PUBLIC)
-       SPL_ME(ParentIterator,  getChildren,      NULL, ZEND_ACC_PUBLIC)
-       SPL_ME(dual_it,         getInnerIterator, NULL, ZEND_ACC_PUBLIC)
+       SPL_MA(ParentIterator,  accept,           RecursiveFilterIterator, hasChildren, NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -1754,9 +1716,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rec_regex_it___construct, 0, 0, 2)
 ZEND_END_ARG_INFO();
 
 static zend_function_entry spl_funcs_RecursiveRegexIterator[] = {
-       SPL_ME(RecursiveRegexIterator, __construct,      arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC)
-       SPL_ME(ParentIterator,         hasChildren,      NULL, ZEND_ACC_PUBLIC)
-       SPL_ME(RecursiveRegexIterator, getChildren,      NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(RecursiveRegexIterator,  __construct,      arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC)
+       SPL_ME(RecursiveFilterIterator, hasChildren,      NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(RecursiveRegexIterator,  getChildren,      NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 #endif