Permalink
Browse files

Merge remote-tracking branch 'remotes/cataphract/strtr_wu94_55' into …

…PHP-5.5

* remotes/cataphract/strtr_wu94_55:
  Fixed inconsequential bug in strtr()
  UPGRADING.INTERNALS: document zend_qsort_r
  Add zend_qsort_r & use it in strtr
  NEWS for bug #63893
  Remove _GNU_SOURCE, add local heap sort
  The compiler can figure this out
  Remove unused block
  strtr() with 2nd param array - optimization
  Refactoring, bugs & leaks
  Optimize strtr w/ 2nd arg array
  • Loading branch information...
2 parents 5cfa916 + 88b82ae commit 1bd193ed36d413f0d919856f65feb35a0b1580f3 @cataphract cataphract committed Jan 15, 2013
Showing with 332 additions and 90 deletions.
  1. +11 −0 UPGRADING.INTERNALS
  2. +9 −3 Zend/zend_qsort.c
  3. +2 −0 Zend/zend_qsort.h
  4. +310 −87 ext/standard/string.c
View
@@ -5,6 +5,7 @@ UPGRADE NOTES - PHP X.Y
1. Internal API changes
a. Streams pooling API
b. Lowercasing and locales
+ c. zend_qsort_r
2. Build system changes
a. Unix build system changes
@@ -53,6 +54,16 @@ such as strcasecmp, will be using locale rules.
Two new functions - zend_binary_strncasecmp_l and zend_binary_strcasecmp_l - added as
locale-based counterparts to zend_binary_strcasecmp and zend_binary_strncasecmp.
+ c. zend_qsort_r
+
+Added the function zend_qsort_r():
+
+typedef int (*compare_r_func_t)(const void *, const void * TSRMLS_DC, void *);
+void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC);
+
+The extra argument it has (relatively to zend_qsort()) is passed to the
+comparison function.
+
========================
2. Build system changes
========================
View
@@ -19,6 +19,7 @@
/* $Id$ */
#include "zend.h"
+#include "zend_qsort.h"
#include <limits.h>
@@ -53,7 +54,7 @@ static void _zend_qsort_swap(void *a, void *b, size_t siz)
}
}
-ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
+ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC)
{
void *begin_stack[QSORT_STACK_SIZE];
void *end_stack[QSORT_STACK_SIZE];
@@ -80,10 +81,10 @@ ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t co
seg2 = end;
while (1) {
- for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC) > 0;
+ for (; seg1 < seg2 && compare(begin, seg1 TSRMLS_CC, arg) > 0;
seg1 += siz);
- for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC) > 0;
+ for (; seg2 >= seg1 && compare(seg2, begin TSRMLS_CC, arg) > 0;
seg2 -= siz);
if (seg1 >= seg2)
@@ -117,6 +118,11 @@ ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t co
}
}
+ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC)
+{
+ zend_qsort_r(base, nmemb, siz, (compare_r_func_t)compare, NULL TSRMLS_CC);
+}
+
/*
* Local Variables:
* c-basic-offset: 4
View
@@ -22,7 +22,9 @@
#define ZEND_QSORT_H
BEGIN_EXTERN_C()
+typedef int (*compare_r_func_t)(const void *, const void * TSRMLS_DC, void *);
ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare TSRMLS_DC);
+ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg TSRMLS_DC);
END_EXTERN_C()
#endif /* ZEND_QSORT_H */
Oops, something went wrong.

0 comments on commit 1bd193e

Please sign in to comment.