]> granicus.if.org Git - php/commitdiff
Reduce unnecessary filter applications when stream is (read|write) only
authorSara Golemon <pollita@php.net>
Thu, 20 Feb 2003 20:05:31 +0000 (20:05 +0000)
committerSara Golemon <pollita@php.net>
Thu, 20 Feb 2003 20:05:31 +0000 (20:05 +0000)
ext/standard/php_fopen_wrapper.c

index 3df43f029cbe30a2e48d6315292512585e1f3d78..d733279119d53eaefc352e36c0b78cdad8dace3e 100644 (file)
@@ -150,6 +150,7 @@ static void php_stream_apply_filter_list(php_stream *stream, char *filterlist, i
 php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
 {
        int fd = -1;
+       int mode_rw = 0;
        php_stream * stream = NULL;
        char *p, *token, *pathdup;
 
@@ -179,6 +180,13 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
        }
 
        if (!strncasecmp(path, "filter/", 7)) {
+               /* Save time/memory when chain isn't specified */
+               if (strchr(mode, 'r') || strchr(mode, '+')) {
+                       mode_rw |= PHP_STREAM_FILTER_READ;
+               }
+               if (strchr(mode, 'w') || strchr(mode, '+') || strchr(mode, 'a')) {
+                       mode_rw |= PHP_STREAM_FILTER_WRITE;
+               }
                pathdup = estrndup(path + 6, strlen(path + 6));
                p = strstr(pathdup, "/resource=");
                if (!p) {
@@ -200,7 +208,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
                        } else if (!strncasecmp(p, "write=", 6)) {
                                php_stream_apply_filter_list(stream, p + 6, 0, 1 TSRMLS_CC);
                        } else {
-                               php_stream_apply_filter_list(stream, p, 1, 1 TSRMLS_CC);
+                               php_stream_apply_filter_list(stream, p, mode_rw & PHP_STREAM_FILTER_READ, mode_rw & PHP_STREAM_FILTER_WRITE TSRMLS_CC);
                        }
                        p = php_strtok_r(NULL, "/", &token);
                }