From 50d214a8ba6f936795afd802fd31763127f3952a Mon Sep 17 00:00:00 2001 From: stekkel Date: Sun, 12 Feb 2006 15:48:11 +0000 Subject: [PATCH] array_shift is slowwwww, this approach is faster. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@10728 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_messages.php | 45 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/functions/imap_messages.php b/functions/imap_messages.php index c6eb5846..f9e0e16e 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -119,29 +119,34 @@ function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) { /** * Sort the message list and crunch to be as small as possible * (overflow could happen, so make it small if possible) + * @param array $aUid array with uid's + * @return string $s message set string */ -function sqimap_message_list_squisher($messages_array) { - if( !is_array( $messages_array ) ) { - return $messages_array; - } - - sort($messages_array, SORT_NUMERIC); - $msgs_str = ''; - while ($messages_array) { - $start = array_shift($messages_array); - $end = $start; - while (isset($messages_array[0]) && $messages_array[0] == $end + 1) { - $end = array_shift($messages_array); - } - if ($msgs_str != '') { - $msgs_str .= ','; - } - $msgs_str .= $start; - if ($start != $end) { - $msgs_str .= ':' . $end; +function sqimap_message_list_squisher($aUid) { + if( !is_array( $aUid ) ) { + return $aUid; + } + sort($aUid, SORT_NUMERIC); + + if (count($aUid)) { + $s = ''; + for ($i=0,$iCnt=count($aUid);$i<$iCnt;++$i) { + $iStart = $aUid[$i]; + $iEnd = $iStart; + while ($i<($iCnt-1) && $aUid[$i+1] == $iEnd +1) { + $iEnd = $aUid[$i+1]; + ++$i; + } + if ($s) { + $s .= ','; + } + $s .= $iStart; + if ($iStart != $iEnd) { + $s .= ':' . $iEnd; + } } } - return $msgs_str; + return $s; } -- 2.25.1