summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2003-02-20 20:05:31 +0000
committerSara Golemon <pollita@php.net>2003-02-20 20:05:31 +0000
commit2002ca0203d71bb5ea3782fb05c10e969dc70589 (patch)
treebb7334442c53df01754d90149ad3aae635b81a32
parente645f20d0708113c08e29f35d76b7264edfc0515 (diff)
downloadphp-git-2002ca0203d71bb5ea3782fb05c10e969dc70589.tar.gz
Reduce unnecessary filter applications when stream is (read|write) only
-rw-r--r--ext/standard/php_fopen_wrapper.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index 3df43f029c..d733279119 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -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);
}