diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-03-04 02:05:28 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-03-04 02:05:28 +0300 |
commit | 2fa8d67a5ce59ba9ba6192481e3c2522c3ff5542 (patch) | |
tree | 9d9d57215f756c387722e74d7d1e1c2de3276a1c /ext/dba/dba.c | |
parent | 2841aa95db84f3563c94c90f84bf7f47ba159a2d (diff) | |
download | php-git-2fa8d67a5ce59ba9ba6192481e3c2522c3ff5542.tar.gz |
Use zend_string* instead of char* for opened_patch handling. Avoid reallocations and improve string reuse.
Diffstat (limited to 'ext/dba/dba.c')
-rw-r--r-- | ext/dba/dba.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c index f4569071f1..8491ff6a38 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -627,7 +627,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) char *file_mode; char mode[4], *pmode, *lock_file_mode = NULL; int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0; - char *opened_path = NULL; + zend_string *opened_path = NULL; char *lock_name; if (ac < 2) { @@ -853,13 +853,9 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */ lock_file_mode = "a+b"; } else { - if (!persistent) { - info->lock.name = opened_path; - } else { - if (opened_path) { - info->lock.name = pestrdup(opened_path, persistent); - efree(opened_path); - } + if (opened_path) { + info->lock.name = pestrndup(opened_path->val, opened_path->len, persistent); + zend_string_release(opened_path); } } } @@ -869,15 +865,11 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (lock_dbf) { /* replace the path info with the real path of the opened file */ pefree(info->path, persistent); - info->path = pestrdup(opened_path, persistent); + info->path = pestrndup(opened_path->val, opened_path->len, persistent); } /* now store the name of the lock */ - if (!persistent) { - info->lock.name = opened_path; - } else { - info->lock.name = pestrdup(opened_path, persistent); - efree(opened_path); - } + info->lock.name = pestrdup(opened_path->val, opened_path->len, persistent); + zend_string_release(opened_path); } } if (!lock_dbf) { |