Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9290

Re: code generation for the ternary operator

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: code generation for the ternary operator
Date Sat, 29 Oct 2011 03:24:11 +0200
Organization A noiseless patient Spider
Lines 28
Message-ID <j8fkk1$eq7$1@dont-email.me> (permalink)
References <29cla79dh934epr5n27cghvupjk77mpuqr@4ax.com> <0GBqq.2475$am1.448@newsfe05.iad>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Date Sat, 29 Oct 2011 01:24:17 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="ylcYE5C53I2wjOlSVZ5APA"; logging-data="15175"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+65Zgo61qDSSgn8QRpgN5J"
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.23) Gecko/20110920 Thunderbird/3.1.15
In-Reply-To <0GBqq.2475$am1.448@newsfe05.iad>
Cancel-Lock sha1:2EQNiFh2GwnbQoL7hY472oxaAlg=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9290

Show key headers only | View raw


On 28/10/2011 19:31, Daniel Pitts allegedly wrote:
> On 10/28/11 6:46 AM, Roedy Green wrote:
>> I wonder if anyone has ever looked at the byte code and/or the hotspot
>> code generated by code like this:
>>
>> final int count = lines * 3 + ( b1 ? 2 : 0 ) + ( b2 ? 2 : 0 ) ;
>>
>> vs:
>>
>> int count = lines *3;
>> if ( b1 ) count += 2;
>> if ( b2 ) count += 2;
>>
>> I wondered how clever it is.  This is just curiosity. This is not
>> critical code.
>>
>> Which style do you prefer?
> 
> If you're going for terseness or obscurity:
> 
> final int count = lines * 3 + b1 != b2 ? 2 : b1 ? 4 : 0;
> 

'!=' is ugly for booleans. Make that a '^' and we have a winner. :)

-- 
DF.
Determinism trumps correctness.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

code generation for the ternary operator Roedy Green <see_website@mindprod.com.invalid> - 2011-10-28 06:46 -0700
  Re: code generation for the ternary operator Jaap Droogers <JaapDroogers@unusable.meel.homelinux.net> - 2011-10-28 16:07 +0200
    Re: code generation for the ternary operator markspace <-@.> - 2011-10-28 08:32 -0700
      Re: code generation for the ternary operator Owen Jacobson <angrybaldguy@gmail.com> - 2011-11-01 01:53 -0400
        Re: code generation for the ternary operator Roedy Green <see_website@mindprod.com.invalid> - 2011-11-01 06:25 -0700
          Source code representation (was: code generation for the ternary operator). Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-01 09:41 -0700
            Re: Source code representation Patricia Shanahan <pats@acm.org> - 2011-11-01 13:46 -0700
              Re: Source code representation Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-01 16:09 -0700
              Re: Source code representation Roedy Green <see_website@mindprod.com.invalid> - 2011-11-01 23:54 -0700
            Re: Source code representation (was: code generation for the ternary operator). Gene Wirchenko <genew@ocis.net> - 2011-11-01 17:33 -0700
              Re: Source code representation (was: code generation for the ternary operator). Roedy Green <see_website@mindprod.com.invalid> - 2011-11-02 01:19 -0700
                Re: Source code representation (was: code generation for the ternary operator). Gene Wirchenko <genew@ocis.net> - 2011-11-02 09:42 -0700
              Re: Source code representation (was: code generation for the ternary operator). Lew <lewbloch@gmail.com> - 2011-11-02 07:45 -0700
              Re: Source code representation Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-02 10:58 -0700
                Re: Source code representation Gene Wirchenko <genew@ocis.net> - 2011-11-02 14:11 -0700
                Re: Source code representation Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-02 15:21 -0700
                Re: Source code representation Gene Wirchenko <genew@ocis.net> - 2011-11-02 16:07 -0700
            Re: Source code representation (was: code generation for the ternary operator). Roedy Green <see_website@mindprod.com.invalid> - 2011-11-01 23:52 -0700
              Re: Source code representation (was: code generation for the ternary operator). Gene Wirchenko <genew@ocis.net> - 2011-11-02 09:47 -0700
                Re: Source code representation (was: code generation for the ternary operator). Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-02 20:58 +0000
                Re: Source code representation Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-02 15:27 -0700
                Re: Source code representation Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-02 23:18 +0000
                Re: Source code representation Lew <lewbloch@gmail.com> - 2011-11-02 17:30 -0700
                Re: Source code representation Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-02 15:30 -0700
                Re: Source code representation Gene Wirchenko <genew@ocis.net> - 2011-11-02 21:30 -0700
                Re: Source code representation Lew <lewbloch@gmail.com> - 2011-11-02 22:07 -0700
            Re: Source code representation Arne Vajhøj <arne@vajhoej.dk> - 2011-11-05 21:01 -0400
      Re: code generation for the ternary operator Arne Vajhøj <arne@vajhoej.dk> - 2011-11-05 20:56 -0400
    Re: code generation for the ternary operator rossum <rossum48@coldmail.com> - 2011-10-29 13:01 +0100
    Re: code generation for the ternary operator Lew <lewbloch@gmail.com> - 2011-10-29 10:46 -0700
  Re: code generation for the ternary operator Henk van Voorthuijsen <voorth@xs4all.nl> - 2011-10-28 08:05 -0700
    Re: code generation for the ternary operator Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-10-28 15:41 +0000
  Re: code generation for the ternary operator Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-28 10:31 -0700
    Re: code generation for the ternary operator Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-10-29 03:24 +0200
  Re: code generation for the ternary operator Wanja Gayk <brixomatic@yahoo.com> - 2011-10-29 00:23 +0200
    Re: code generation for the ternary operator Lew <lewbloch@gmail.com> - 2011-10-29 10:50 -0700
      Re: code generation for the ternary operator Wanja Gayk <brixomatic@yahoo.com> - 2011-11-01 13:36 +0100
  Re: code generation for the ternary operator Michal Kleczek <kleku@poczta.onet.pl> - 2011-10-31 17:38 +0100

csiph-web