RESOLVE MAJOR BOTTOLNECK (and even bugs) of banana :
authorx2000habouzit <x2000habouzit>
Fri, 31 Dec 2004 15:04:42 +0000 (15:04 +0000)
committerx2000habouzit <x2000habouzit>
Fri, 31 Dec 2004 15:04:42 +0000 (15:04 +0000)
building the Whole spool for xorg.promo.2002 with more than 1800 posts takes less than 3 secs !!!
the 2 array_map of the headerDecode function took more than 11secs before to do their job (for the both)
---> now it takes less than the second !

oh yeah !

include/encoding.inc.php

index 256146e..9d30000 100644 (file)
  * @param STRING $_value string to decode
  */
 
-function headerDecode($_value) {
-    if (eregi('=\?.*\?.\?.*\?=',$_value)) { // is there anything encoded ?
-        if (eregi('=\?(.*)\?Q\?.*\?=',$_value,$charset)) {  // quoted-printable decoding
-            $result1 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\1',$_value);
-            $result2 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\2',$_value);
-            $result3 = eregi_replace('(.*)=\?.*\?Q\?(.*)\?=(.*)','\3',$_value);
-            $result2 = str_replace("_"," ",quoted_printable_decode($result2));
-            if ($charset[1] == "UTF-8") {
-                $result2 = utf8_decode($result2);
-            }
-            $newvalue = $result1.$result2.$result3;
-        }
-        if (eregi('=\?(.*)\?B\?.*\?=',$_value,$charset)) {  // base64 decoding
-            $result1 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\1',$_value);
-            $result2 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\2',$_value);
-            $result3 = eregi_replace('(.*)=\?.*\?B\?(.*)\?=(.*)','\3',$_value);
-            $result2 = base64_decode($result2);
-            if ($charset[1] == "UTF-8") {
-                $result2 = utf8_decode($result2);
-            }
-            $newvalue = $result1.$result2.$result3;
-        }
-        if (!isset($newvalue)) { // nothing of the above, must be an unknown encoding...
-            $newvalue = $_value;
-        } else {
-            $newvalue=headerDecode($newvalue);  // maybe there are more encoded
-        }
-        return($newvalue);                    // parts
-    } else {   // there wasn't anything encoded, return the original string
-        return($_value);
-    }
+function _headerdecode($charset, $c, $str) {
+    $s = ($c == 'Q') ? quoted_printable_decode($str) : base64_decode($str);
+    $s = iconv($charset, 'iso-8859-15', $s);
+    return str_replace('_', ' ', $s);
+}
+function headerDecode($value) {
+    $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value);
+    return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val);
 }
 ?>