From 2fa8d67a5ce59ba9ba6192481e3c2522c3ff5542 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 4 Mar 2015 02:05:28 +0300 Subject: Use zend_string* instead of char* for opened_patch handling. Avoid reallocations and improve string reuse. --- ext/bz2/bz2.c | 18 +++--------------- ext/bz2/php_bz2.h | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'ext/bz2') diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 9b59942f26..969c5e131c 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -235,7 +235,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, - char **opened_path, + zend_string **opened_path, php_stream_context *context STREAMS_DC) { php_stream *retstream = NULL, *stream = NULL; @@ -266,20 +266,8 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, bz_file = BZ2_bzopen(path_copy, mode); if (opened_path && bz_file) { -#ifdef VIRTUAL_DIR - *opened_path = path_copy; - path_copy = NULL; -#else - *opened_path = estrdup(path_copy); -#endif - } - -#ifdef VIRTUAL_DIR - if (path_copy) { - efree(path_copy); + *opened_path = zend_string_init(path_copy, strlen(path_copy), 0); } -#endif - path_copy = NULL; if (bz_file == NULL) { /* that didn't work, so try and get something from the network/wrapper */ @@ -296,7 +284,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, * failed. */ if (opened_path && !bz_file && mode[0] == 'w') { - VCWD_UNLINK(*opened_path); + VCWD_UNLINK((*opened_path)->val); } } diff --git a/ext/bz2/php_bz2.h b/ext/bz2/php_bz2.h index b3c0725086..b1aa4ca97c 100644 --- a/ext/bz2/php_bz2.h +++ b/ext/bz2/php_bz2.h @@ -47,7 +47,7 @@ extern zend_module_entry bz2_module_entry; # define PHP_BZ2_API #endif -PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC); +PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, const char *mode, php_stream *innerstream STREAMS_DC); #define php_stream_bz2open_from_BZFILE(bz, mode, innerstream) _php_stream_bz2open_from_BZFILE((bz), (mode), (innerstream) STREAMS_CC) -- cgit v1.2.1