com php-src: Avoiding str duplication: ext/standard/pack.c

From: Date: Tue, 13 Jun 2017 06:00:53 +0000
Subject: com php-src: Avoiding str duplication: ext/standard/pack.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-98076@lists.php.net to get a copy of this message
Commit: dc098b09f8d9203b7e238bb2d18ab5771c7045a3 Author: Xinchen Hui <laruence@gmail.com> Tue, 13 Jun 2017 14:00:53 +0800 Parents: 42b3bf93fbdd7d8de2bccac01de21d49897b546e Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dc098b09f8d9203b7e238bb2d18ab5771c7045a3 Log: Avoiding str duplication Changed paths: M ext/standard/pack.c Diff: diff --git a/ext/standard/pack.c b/ext/standard/pack.c index 680e67c..7b974ca 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -969,7 +969,7 @@ PHP_FUNCTION(unpack) zend_long len = (inputlen - inputpos) * 2; /* Remaining */ int nibbleshift = (type == 'h') ? 0 : 4; int first = 1; - char *buf; + zend_string *buf; zend_long ipos, opos; /* If size was given take minimum of len and size */ @@ -981,7 +981,7 @@ PHP_FUNCTION(unpack) len -= argb % 2; } - buf = emalloc(len + 1); + buf = zend_string_alloc(len, 0); for (ipos = opos = 0; opos < len; opos++) { char cc = (input[inputpos + ipos] >> nibbleshift) & 0xf; @@ -992,7 +992,7 @@ PHP_FUNCTION(unpack) cc += 'a' - 10; } - buf[opos] = cc; + ZSTR_VAL(buf)[opos] = cc; nibbleshift = (nibbleshift + 4) & 7; if (first-- == 0) { @@ -1001,9 +1001,8 @@ PHP_FUNCTION(unpack) } } - buf[len] = '\0'; - add_assoc_stringl(return_value, n, buf, len); - efree(buf); + ZSTR_VAL(buf)[len] = '\0'; + add_assoc_str(return_value, n, buf); break; }

« previous php.cvs (#98076) next »