Re: Intro and new extension: jsmin

From: Date: Tue, 25 Sep 2012 16:38:16 +0000
Subject: Re: Intro and new extension: jsmin
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-9846@lists.php.net to get a copy of this message
On 2012-09-17 17:04:22 +0000, Johannes Schlüter said:
     1. the PHP Coding standard (see php-src/CODING_STANDARD) suggests
        to always use curly braces, even with a one line if. No big
        issue but, well ;-)
     2. if (!javascript_len) RETURN_NULL();  -- i would consider an
        empty string to be "valid" input, and would expect the empty
        string to be the proper result then, not NULL
     3. in jsmin() your creating a copy (minified =
        estrndup(jmo->buffer->c, jmo->buffer->len);) of a buffer and
        then in PHP_FUNCTION(jsmin) you are copying it, again while not
        freeing the intermediate copy. changing the 1 in the
        ZVAL_STRING() call to a 0 should avoid the copy (also build your
        PHP using --enable-debug, then this should emit a note)
     4. using RETURN_STRING() instead of ZVAL_STRING(return_value) is a
        it nicer to read ;-)
     5. in jsmin() you know the length (jmo->buffer->len),you should use
        that to fill the return_value inside the PHP_FUNCTION (either
        return the length as additional parameter via pointer, or pass
        the return_value as zval* from the PHP_FUNCTION to jsmin())
Followed your advice, as well as rrichards from outside the list, and cleaned up implementation.

« previous php.pecl.dev (#9846) next »