Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67425 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62098 invoked from network); 14 May 2013 21:18:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2013 21:18:12 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.51 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.51 mail-oa0-f51.google.com Received: from [209.85.219.51] ([209.85.219.51:32917] helo=mail-oa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/41-48911-41AA2915 for ; Tue, 14 May 2013 17:18:12 -0400 Received: by mail-oa0-f51.google.com with SMTP id f4so1298395oah.10 for ; Tue, 14 May 2013 14:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=/FEN92tcqTUA8EvRwdePijGN0dre4Akw4X4TJwAwAcA=; b=FVwQ/MQ4rVC20iQieJ9N1FsPJEqAbdlSFy3VnchJ3ZXu4htSSmAnDmOK+Yh6vEIbJE ckQaeJgEEdG1TCTBO7bRCc63BizFJLp0kH4eZ+bnlGHzs/y5bGVghKCKoY5l1TRZqYy+ /D33kYYUevsNENkk9FMxqbeEub2K5vWT5S/vhNIDQ4/mBcUkuNalst56rxJJAsAdeLx7 w4N54korsTfbReEpZg3nLpw5fj+mClCJXhn+ApqJAelJf9qmUSlZy/z4YXvysEbvGDml pw87j73symTEUGQCrOGDaR52bVykIfnwW3LXHPWvqTAwEzUu87nKXg+JE3sSJNvOx/AP +aBw== MIME-Version: 1.0 X-Received: by 10.182.86.6 with SMTP id l6mr15313549obz.6.1368566289568; Tue, 14 May 2013 14:18:09 -0700 (PDT) Received: by 10.182.49.136 with HTTP; Tue, 14 May 2013 14:18:09 -0700 (PDT) In-Reply-To: References: Date: Tue, 14 May 2013 23:18:09 +0200 Message-ID: To: Dmitry Stogov Cc: PHP internals Content-Type: multipart/alternative; boundary=089e0149c4688ae95204dcb42ba0 Subject: Re: [PHP-DEV] [RFC] Internal operator overloading and GMP improvements From: nikita.ppv@gmail.com (Nikita Popov) --089e0149c4688ae95204dcb42ba0 Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 14, 2013 at 7:43 AM, Dmitry Stogov wrote: > Hi Nikita, > > Few final notes: > > - I wouldn't change zend_object_compare_t into > zend_object_compare_objects_t. It would be better to name the new function > as zend_object_compare_zvals_t. (It's just for better backward > compatibility) > Done. Should I also call the handler itself compare_zvals then or can that stay as just compare? - Increment and decrement operators in PHP may have different semantic than > +=1, but I it's probably OK to use ADD/SUB for them. > I think we should just introduce this once a use case comes up. > - In some cases you insert call to zend_object_do_operation into the most > probable path (e.g. in mod_function). This would cause at lease 2 > additional comparisons and may be conditional jumps. I think it would be > better to check for most probable operand types first... > For $a % $b the most common cases are already handled by fast_mod_function. mod_function is only directly called when doing $a %= $b. But in any case, I'm not sure how I could test the more probable cases first, as the next thing the code does is call convert_to_long. Of course I could copy the code from fast_mod_function in there, but that doesn't sounds like a good idea. I think the only operation that could really be a performance concern is concat_function, because that's a common operation without a fast_ variant. But even in that case I could not measure a difference in runtime (taking averages on 100M concatenations). > 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. > What would be the benefits? Better performance? Imho using a switch is handier when implementing the operators, because it requires less boilerplate code (no need to repeat function signature, variables, shared code etc). > Also it may make sense to think about overloading of unary operators to > provide a solid decision. > You mean being able to overload unary + and - directly rather than the current 0+$a / 0-$a transformation? I can see that this might be useful, but not sure it's worth it (would have to introduce new opcodes for that). I'd do the same as with the increment/decrement operators here: Only implement them once there is a specific use case. In case you think about user-level operator overloading in the future (that > may make sense :) it would be better to design them all together. > I was thinking about that too, but from the previous discussions on the topic I figured that there is zero chance for having that in PHP :/ Thanks for the feedback! Nikita --089e0149c4688ae95204dcb42ba0--