RFR (S) 8136500: Integer/Long getChars and stringSize should be more idiomatic
aleksey.shipilev at oracle.com
Sun Nov 22 19:59:24 UTC 2015
On 11/22/2015 01:55 AM, Ivan Gerasimov wrote:
>>> Second, I think, the code of stringSize() might be better inlined, if it
>>> was used only once.
>> No-no! That's a helpful little fella. Not-yet-integrated Indify String
>> Concat uses Integer/Long.stringSize.
> I didn't really propose to manually inline the stringSize() into the
> calling code.
> What I was trying to say was that if we replace the code "int size = (i
> < 0) ? stringSize(-i) + 1 : stringSize(i)", which calls stringSize()
> twice, with something, which calls it only once, it might be easier for
> compiler to inline it.
> Sorry, I didn't make it clear :)
Ah, that "only once" confused me. Yes, that makes sense. In fact, I
think we should just soak the negative check into the stringSize, given
that all the usages are doing the checks externally. This exposes the
MIN_VALUE checks back, but it seems a fair trade for cleaner code; the
performance is still on par with previous revisions. And, this also
caters for AbstractStringBuilders, as you and Fabian wanted.
More information about the core-libs-dev