Re: [RFC] Internal operator overloading and GMP improvements
| From: | Dmitry Stogov | Date: | Mon, 13 May 2013 10:25:34 +0000 |
| Subject: | Re: [RFC] Internal operator overloading and GMP improvements | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-67417@lists.php.net to get a copy of this message | ||
Hi,
On Mon, May 13, 2013 at 1:24 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Mon, May 13, 2013 at 7:49 AM, Dmitry Stogov <dmitry@zend.com> wrote:
>
>> Hi Nikita,
>>
>> The patch looks quite good.
>> However, it must slow down each comparison operator (even if it compares
>> two integers).
>>
> In most cases it shouldn't, as the comparisons usually go through the
> fast_is_*_functions, which have special handling for integers and doubles.
> is_equal_function itself for example is only used in the implementation of
> ZEND_CASE (why? shouldn't we use the fast_ one here too?) and stuff like
> array_search.
>
Ahh, you are right :)
>
> I would suggest overloading of CMP operator instead of separate <, <=, ==,
>> !=, >, >=.
>>
>
> But yeah, that sounds like a better solution. The advantages I see:
> a) It will automatically work with sorting functions (and other stuff
> using compare_function). This is a pretty big plus.
> b) You don't have to implement the same (or similar) code for four (or
> six) operators.
> c) It (at least partially) also solves the concerns raised by Sara.
>
I'm glad, you are agree :)
> Would need an additional object handler though (as compare_objects works
> only on objects, so it's currently not possible to support something like
> $gmp == 0).
>
>
Or may be we may introduce additional opcode (or even pseudo-opcode)
ZEND_CMP to do it in the same way.
Also it may be better to use a table of callbacks for each overloaded
operand instead of single one that need to do switch anyway.
Thanks. Dmitry.
> Nikita
>