PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_qsort.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 44 47 93.6 %
Date: 2014-12-15 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        | 
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Sterling Hughes <sterling@php.net>                          |
      16             :    +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "zend.h"
      22             : 
      23             : #include <limits.h>
      24             : 
      25             : #define QSORT_STACK_SIZE (sizeof(size_t) * CHAR_BIT)
      26             : 
      27      222380 : static void _zend_qsort_swap(void *a, void *b, size_t siz)
      28             : {
      29             :         register char  *tmp_a_char;
      30             :         register char  *tmp_b_char;
      31             :         register int   *tmp_a_int;
      32             :         register int   *tmp_b_int;
      33             :         register size_t i;
      34             :         int             t_i;
      35             :         char            t_c;
      36             : 
      37      222380 :         tmp_a_int = (int *) a;
      38      222380 :         tmp_b_int = (int *) b;
      39             : 
      40      762136 :         for (i = sizeof(int); i <= siz; i += sizeof(int)) {
      41      539756 :                 t_i = *tmp_a_int;
      42      539756 :                 *tmp_a_int++ = *tmp_b_int;
      43      539756 :                 *tmp_b_int++ = t_i;
      44             :         }
      45             : 
      46      222380 :         tmp_a_char = (char *) tmp_a_int;
      47      222380 :         tmp_b_char = (char *) tmp_b_int;
      48             : 
      49      222380 :         for (i = i - sizeof(int) + 1; i <= siz; ++i) {
      50           0 :                 t_c = *tmp_a_char;
      51           0 :                 *tmp_a_char++ = *tmp_b_char;
      52           0 :                 *tmp_b_char++ = t_c;
      53             :         }
      54      222380 : }
      55             : 
      56        3224 : ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
      57             : {
      58             :         void           *begin_stack[QSORT_STACK_SIZE];
      59             :         void           *end_stack[QSORT_STACK_SIZE];
      60             :         register char  *begin;
      61             :         register char  *end;
      62             :         register char  *seg1;
      63             :         register char  *seg2;
      64             :         register char  *seg2p;
      65             :         register int    loop;
      66             :         uint            offset;
      67             : 
      68        3224 :         begin_stack[0] = (char *) base;
      69        3224 :         end_stack[0]   = (char *) base + ((nmemb - 1) * siz);
      70             : 
      71       44451 :         for (loop = 0; loop >= 0; --loop) {
      72       41228 :                 begin = begin_stack[loop];
      73       41228 :                 end   = end_stack[loop];
      74             : 
      75      142992 :                 while (begin < end) {
      76       60537 :                         offset = (end - begin) >> 1;
      77       60537 :                         _zend_qsort_swap(begin, begin + (offset - (offset % siz)), siz);
      78             : 
      79       60537 :                         seg1 = begin + siz;
      80       60537 :                         seg2 = end;
      81             : 
      82             :                         while (1) {
      83      664023 :                                 for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC) > 0;
      84      340335 :                                      seg1 += siz);
      85             : 
      86      641210 :                                 for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC) > 0;
      87      317522 :                                      seg2 -= siz);
      88             :                                 
      89      161843 :                                 if (seg1 >= seg2)
      90       60536 :                                         break;
      91             :                                 
      92      101307 :                                 _zend_qsort_swap(seg1, seg2, siz);
      93             : 
      94      101307 :                                 seg1 += siz;
      95      101307 :                                 seg2 -= siz;
      96      101307 :                         }
      97             : 
      98       60536 :                         _zend_qsort_swap(begin, seg2, siz);
      99             : 
     100       60536 :                         seg2p = seg2;
     101             :                         
     102       60536 :                         if ((seg2p - begin) <= (end - seg2p)) {
     103       40383 :                                 if ((seg2p + siz) < end) {
     104       23604 :                                         begin_stack[loop] = seg2p + siz;
     105       23604 :                                         end_stack[loop++] = end;
     106             :                                 }
     107       40383 :                                 end = seg2p - siz;
     108             :                         }
     109             :                         else {
     110       20153 :                                 if ((seg2p - siz) > begin) {
     111       14400 :                                         begin_stack[loop] = begin;
     112       14400 :                                         end_stack[loop++] = seg2p - siz;
     113             :                                 }
     114       20153 :                                 begin = seg2p + siz;
     115             :                         }
     116             :                 }
     117             :         }
     118        3223 : }
     119             : 
     120             : /* 
     121             :  * Local Variables:
     122             :  * c-basic-offset: 4 
     123             :  * tab-width: 4
     124             :  * End:
     125             :  * vim600: fdm=marker
     126             :  * vim: noet sw=4 ts=4
     127             :  */

Generated by: LCOV version 1.10

Generated at Mon, 15 Dec 2014 17:02:38 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.