sterling                Thu Mar 15 20:23:58 2001 EDT

  Modified files:              
    /php4/ext/bz2       bz2.c 
  Log:
  Slightly modified fix from jeremy brand <[EMAIL PROTECTED]>.  he 
  correctly pointed out that allocating the buffer to a little more than
  need (exact formula is in the code) will save the need to keep retrying
  the compression.
  
  
  
Index: php4/ext/bz2/bz2.c
diff -u php4/ext/bz2/bz2.c:1.11 php4/ext/bz2/bz2.c:1.12
--- php4/ext/bz2/bz2.c:1.11     Thu Mar 15 17:21:24 2001
+++ php4/ext/bz2/bz2.c  Thu Mar 15 20:23:58 2001
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
  
-/* $Id: bz2.c,v 1.11 2001/03/16 01:21:24 sniper Exp $ */
+/* $Id: bz2.c,v 1.12 2001/03/16 04:23:58 sterling Exp $ */
 
  
 #include "php.h"
@@ -276,9 +276,11 @@
        convert_to_string_ex(source);
        
        /* Assign them to easy to use variables, dest_len is initially the length of 
the data
-          because, the compression buffer should be smaller than the size of the data 
passed */
+          + .01 x length of data + 600 which is the largest size the results of the 
+compression 
+          could possibly be, at least that's what the libbz2 docs say (thanks to 
[EMAIL PROTECTED] 
+          for pointing this out).  */
        source_len = Z_STRLEN_PP(source);
-       dest_len   = Z_STRLEN_PP(source);
+       dest_len   = Z_STRLEN_PP(source) + (0.01 * Z_STRLEN_PP(source)) + 600;
        
        /* Allocate the destination buffer */
        dest = emalloc(dest_len + 1);
@@ -293,20 +295,8 @@
                convert_to_long_ex(zwork_factor);
                work_factor = Z_LVAL_PP(zwork_factor);
        }
-       
-       /* Compression loop */
-       do {
-               /* Handle the (re)allocation of the buffer */
-               size = dest_len * iter;
-               if (iter > 1) {
-                       dest = erealloc(dest, size);
-               }
-               iter++;
-               
-               /* Try and perform the compression */
-               error = BZ2_bzBuffToBuffCompress(dest, &size, Z_STRVAL_PP(source), 
source_len, block_size, 0, work_factor);
-       } while (error == BZ_OUTBUFF_FULL);
-       
+
+       error = BZ2_bzBuffToBuffCompress(dest, &size, Z_STRVAL_PP(source), source_len, 
+block_size, 0, work_factor);
        if (error != BZ_OK) {
                RETVAL_LONG(error);
        } else {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to