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: 47 50 94.0 %
Date: 2014-07-21 Functions: 3 3 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             : #include "zend_qsort.h"
      23             : 
      24             : #include <limits.h>
      25             : 
      26             : #define QSORT_STACK_SIZE (sizeof(size_t) * CHAR_BIT)
      27             : 
      28      244128 : static void _zend_qsort_swap(void *a, void *b, size_t siz)
      29             : {
      30             :         register char  *tmp_a_char;
      31             :         register char  *tmp_b_char;
      32             :         register int   *tmp_a_int;
      33             :         register int   *tmp_b_int;
      34             :         register size_t i;
      35             :         int             t_i;
      36             :         char            t_c;
      37             : 
      38      244128 :         tmp_a_int = (int *) a;
      39      244128 :         tmp_b_int = (int *) b;
      40             : 
      41      833912 :         for (i = sizeof(int); i <= siz; i += sizeof(int)) {
      42      589784 :                 t_i = *tmp_a_int;
      43      589784 :                 *tmp_a_int++ = *tmp_b_int;
      44      589784 :                 *tmp_b_int++ = t_i;
      45             :         }
      46             : 
      47      244128 :         tmp_a_char = (char *) tmp_a_int;
      48      244128 :         tmp_b_char = (char *) tmp_b_int;
      49             : 
      50      244128 :         for (i = i - sizeof(int) + 1; i <= siz; ++i) {
      51           0 :                 t_c = *tmp_a_char;
      52           0 :                 *tmp_a_char++ = *tmp_b_char;
      53           0 :                 *tmp_b_char++ = t_c;
      54             :         }
      55      244128 : }
      56             : 
      57        3270 : ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC)
      58             : {
      59             :         void           *begin_stack[QSORT_STACK_SIZE];
      60             :         void           *end_stack[QSORT_STACK_SIZE];
      61             :         register char  *begin;
      62             :         register char  *end;
      63             :         register char  *seg1;
      64             :         register char  *seg2;
      65             :         register char  *seg2p;
      66             :         register int    loop;
      67             :         uint            offset;
      68             : 
      69        3270 :         begin_stack[0] = (char *) base;
      70        3270 :         end_stack[0]   = (char *) base + ((nmemb - 1) * siz);
      71             : 
      72       49494 :         for (loop = 0; loop >= 0; --loop) {
      73       46225 :                 begin = begin_stack[loop];
      74       46225 :                 end   = end_stack[loop];
      75             : 
      76      159358 :                 while (begin < end) {
      77       66909 :                         offset = (end - begin) >> 1;
      78       66909 :                         _zend_qsort_swap(begin, begin + (offset - (offset % siz)), siz);
      79             : 
      80       66909 :                         seg1 = begin + siz;
      81       66909 :                         seg2 = end;
      82             : 
      83             :                         while (1) {
      84      694934 :                                 for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC, arg) > 0;
      85      340494 :                                      seg1 += siz);
      86             : 
      87      710504 :                                 for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC, arg) > 0;
      88      356064 :                                      seg2 -= siz);
      89             :                                 
      90      177219 :                                 if (seg1 >= seg2)
      91       66908 :                                         break;
      92             :                                 
      93      110311 :                                 _zend_qsort_swap(seg1, seg2, siz);
      94             : 
      95      110311 :                                 seg1 += siz;
      96      110311 :                                 seg2 -= siz;
      97      110311 :                         }
      98             : 
      99       66908 :                         _zend_qsort_swap(begin, seg2, siz);
     100             : 
     101       66908 :                         seg2p = seg2;
     102             :                         
     103       66908 :                         if ((seg2p - begin) <= (end - seg2p)) {
     104       46043 :                                 if ((seg2p + siz) < end) {
     105       28474 :                                         begin_stack[loop] = seg2p + siz;
     106       28474 :                                         end_stack[loop++] = end;
     107             :                                 }
     108       46043 :                                 end = seg2p - siz;
     109             :                         }
     110             :                         else {
     111       20865 :                                 if ((seg2p - siz) > begin) {
     112       14481 :                                         begin_stack[loop] = begin;
     113       14481 :                                         end_stack[loop++] = seg2p - siz;
     114             :                                 }
     115       20865 :                                 begin = seg2p + siz;
     116             :                         }
     117             :                 }
     118             :         }
     119        3269 : }
     120             : 
     121        3231 : ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
     122             : {
     123        3231 :         zend_qsort_r(base, nmemb, siz, (compare_r_func_t)compare, NULL TSRMLS_CC);
     124        3230 : }
     125             : 
     126             : /* 
     127             :  * Local Variables:
     128             :  * c-basic-offset: 4 
     129             :  * tab-width: 4
     130             :  * End:
     131             :  * vim600: fdm=marker
     132             :  * vim: noet sw=4 ts=4
     133             :  */

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:03 +0000 (28 hours ago)

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