String concatenation tweaks
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Fri Jun 5 14:31:41 UTC 2015
Yes, Of course not completely.
This is decompile of javac produced bytecode.
String chart = " var chart = new Highcharts.Chart({\n
chart: {\n zoomType: 'x',\n height: "
+ chartHeight + ",\n"
+ " width: " + chartWidth + ",\n"
+ " type: 'column',\n"
+ " plotBackgroundImage: '',\n"
+ " renderTo: '" + id + "',\n"
+ " \tevents: {\n"
+ " \t\tclick: function(e) {\n"
+ " \t\t\t//CHARTCLICK_HANDLER_CODE\n"
+ " \t\t}\n" + " \t}\n"
+ " },\n";
As you can see javac generates more than 6 calls to append() :)
On Fri, Jun 5, 2015 at 6:22 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> Ali,
> javac already concatenates constant strings,
> so your first example generates only 6 calls to append() :)
>
> cheers,
> Rémi
>
>
> On 06/05/2015 03:45 PM, Ali Ebrahimi wrote:
>
> Hi,
>
>
> On Thu, Jun 4, 2015 at 9:43 PM, Aleksey Shipilev <
> aleksey.shipilev at oracle.com> wrote:
>
>> On 06/04/2015 04:59 PM, Ali Ebrahimi wrote:
>> > Please add String Interpolation and Multi-line String: in that case we
>> > would have better answer for problem.
>>
>> Neither String interpolation nor multi-line Strings are supported by
>> current Java language, so throwing these in mix promotes the issue into
>> extending the language. Not fun.
>>
> I think, I don't say java already support them, but I beleave java should
> support them.
>
>>
>> In addition, Multi-line Strings is purely a syntax issue, not the
>> bytecode interface one, and so it seems rather unrelated.
>>
> I don't think so.
> consider this code:
>
> String chart = " var chart = new Highcharts.Chart({\n" +
> " chart: {\n" +
> " zoomType: 'x',\n" +
> " height: " + chartHeight + ",\n" +
> " width: " + chartWidth + ",\n" +
> " type: 'column',\n" +
> " plotBackgroundImage: '',\n" +
> " renderTo: '" + id + "',\n" +
> " \tevents: {\n" +
> " \t\tclick: function(e) {\n" +
> " \t\t\t//CHARTCLICK_HANDLER_CODE\n" +
> " \t\t}\n" +
> " \t}\n" +
> " },\n";
> needs 20 sb.append call
>
> vs multi-line string
>
> String chart = " var chart = new Highcharts.Chart({\n
> chart: {\n
> zoomType: 'x',\n
> height: " + chartHeight + ",\n
> width: " + chartWidth + ",\n
> type: 'column',\n
> plotBackgroundImage: ' ',\n
> renderTo: '" + id + "',\n
> \tevents: {\n
> \t\tclick: function(e) {\n
> \t\t\t//CHARTCLICK_HANDLER_CODE\n
> \t\t}\n
> \t}\n
> },\n";
> 6 sb.append call
>
> vs multi-line string & String Interpolation
>
> String chart = $" var chart = new Highcharts.Chart({\n
> chart: {\n
> zoomType: 'x',\n
> height: ${chartHeight },\n
> width: ${chartWidth },\n
> type: 'column',\n
> plotBackgroundImage: ' ',\n
> renderTo: '${ id }',\n
> \tevents: {\n
> \t\tclick: function(e) {\n
> \t\t\t//CHARTCLICK_HANDLER_CODE\n
> \t\t}\n
> \t}\n
> },\n";
> This depend on implementation detail but max 6 sb.append call
> I think with multi-line string & String Interpolation javac have better
> view of overall string expressions and can generate optimized bytecode.
>
> In other side, we have improved code readability.
>
> --
>
> Best Regards,
> Ali Ebrahimi
>
>
>
--
Best Regards,
Ali Ebrahimi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150605/e508f7ad/attachment-0001.html>
More information about the compiler-dev
mailing list