Reduce SimplePie memory usage. Props link92. fixes #10147 for trunk

git-svn-id: http://svn.automattic.com/wordpress/trunk@11599 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-06-18 19:38:08 +00:00
parent b37b56a339
commit 3737553e65
1 changed files with 29 additions and 47 deletions

View File

@ -751,21 +751,24 @@ class SimplePie
*/
function __destruct()
{
if (!empty($this->data['items']))
if (version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled())
{
foreach ($this->data['items'] as $item)
if (!empty($this->data['items']))
{
$item->__destruct();
foreach ($this->data['items'] as $item)
{
$item->__destruct();
}
unset($item, $this->data['items']);
}
unset($this->data['items']);
}
if (!empty($this->data['ordered_items']))
{
foreach ($this->data['ordered_items'] as $item)
if (!empty($this->data['ordered_items']))
{
$item->__destruct();
foreach ($this->data['ordered_items'] as $item)
{
$item->__destruct();
}
unset($item, $this->data['ordered_items']);
}
unset($this->data['ordered_items']);
}
}
@ -3082,7 +3085,10 @@ class SimplePie_Item
*/
function __destruct()
{
unset($this->feed);
if (version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled())
{
unset($this->feed);
}
}
function get_item_tags($namespace, $tag)
@ -5682,14 +5688,6 @@ class SimplePie_Source
return md5(serialize($this->data));
}
/**
* Remove items that link back to this before destroying this object
*/
function __destruct()
{
unset($this->item);
}
function get_source_tags($namespace, $tag)
{
if (isset($this->data['child'][$namespace][$tag]))
@ -8954,23 +8952,12 @@ class SimplePie_Misc
function parse_url($url)
{
static $cache = array();
if (isset($cache[$url]))
preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $url, $match);
for ($i = count($match); $i <= 9; $i++)
{
return $cache[$url];
}
elseif (preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $url, $match))
{
for ($i = count($match); $i <= 9; $i++)
{
$match[$i] = '';
}
return $cache[$url] = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
}
else
{
return $cache[$url] = array('scheme' => '', 'authority' => '', 'path' => '', 'query' => '', 'fragment' => '');
$match[$i] = '';
}
return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
}
function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
@ -10809,36 +10796,31 @@ class SimplePie_Misc
*/
function codepoint_to_utf8($codepoint)
{
static $cache = array();
$codepoint = (int) $codepoint;
if (isset($cache[$codepoint]))
if ($codepoint < 0)
{
return $cache[$codepoint];
}
elseif ($codepoint < 0)
{
return $cache[$codepoint] = false;
return false;
}
else if ($codepoint <= 0x7f)
{
return $cache[$codepoint] = chr($codepoint);
return chr($codepoint);
}
else if ($codepoint <= 0x7ff)
{
return $cache[$codepoint] = chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0xffff)
{
return $cache[$codepoint] = chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0x10ffff)
{
return $cache[$codepoint] = chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else
{
// U+FFFD REPLACEMENT CHARACTER
return $cache[$codepoint] = "\xEF\xBF\xBD";
return "\xEF\xBF\xBD";
}
}