Re: com php-src: Faster sorting algo: UPGRADING Zend/Makefile.am Zend/tests/methods-on-non-objects-usort.phpt Zend/zend_API.c Zend/zend_hash.c
Zend/zend_hash.h Zend/zend_ini.c Zend/zend_llist.c Zend/zend_qsort.c Zend/zend_qsort.h Zend/zend_sort.c Zend/zend_sort.h Zend/zend_ts_hash.c
Zend/zend_types.h configure.in ext/ereg/ereg.c ext/intl/collator/collator_sort.c ext/phar/dirstream.c ext/phar/phar_internal.h ext/standard/array.c
ext/standard/info.c ex

From: Date: Mon, 19 Jan 2015 05:42:51 +0000
Subject: Re: com php-src: Faster sorting algo: UPGRADING Zend/Makefile.am Zend/tests/methods-on-non-objects-usort.phpt Zend/zend_API.c Zend/zend_hash.c
Zend/zend_hash.h Zend/zend_ini.c Zend/zend_llist.c Zend/zend_qsort.c Zend/zend_qsort.h Zend/zend_sort.c Zend/zend_sort.h Zend/zend_ts_hash.c
Zend/zend_types.h configure.in ext/ereg/ereg.c ext/intl/collator/collator_sort.c ext/phar/dirstream.c ext/phar/phar_internal.h ext/standard/array.c
ext/standard/info.c ex
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-80768@lists.php.net to get a copy of this message
> On 19 Jan 2015, at 05:00, Andrea Faulds <ajf@ajf.me> wrote: > > Related: since we have no Perl-like spaceship operator ($a <=> $b), writing comparison > functions is unnecessarily complex in the common case, as you must produce -1, 0, 1 yourself. > > Could we expose a cmp() or compare() function that calls our internal comparison operator? This > would make writing custom sort functions a lot nicer, and quite possibly improve some other kinds of > code. > > That would also mean a future sorting API could unify user sorts and non-user sorts: just make > the default callback be cmp(). > > Usage would be like this: > > cmp(1, 2); // 1 > cmp(1, 1); // 0 > cmp(2, 1); // 1 > > Essentially, exactly like the spaceship in Perl, but a function. > > Thoughts? I went ahead and implemented it, since it’s so trivial: https://github.com/php/php-src/pull/1006 Should I write an RFC, or could we just merge this without needing one? I’m also wondering if numcmp(), to do “numeric comparison” might also be a good idea. Currently it’s the same as cmp((float)$val1, (float)$val2); but that might (and probably should, that leads to inaccurate sorting!) change in future. Thoughts? -- Andrea Faulds http://ajf.me/

« previous php.internals (#80768) next »