deduplicating lambda methods
B. Blaser
bsrbnd at gmail.com
Wed Mar 21 20:15:03 UTC 2018
I'm not very imaginative but for example:
java.util.function.BiFunction<String, Character, Integer> f = (s,c) -> {
Integer i=0;
for (; i<s.length() && s.charAt(i) != c; i++) ;
return i;
};
System.out.println(f.apply("abc", 'b'));
f = (s,c) -> {
Integer i=0;
for (; i<s.length() && s.charAt(i) != c; i++) {}
return i;
};
System.out.println(f.apply("def", 'g'));
Bernard
On 21 March 2018 at 20:19, Brian Goetz <brian.goetz at oracle.com> wrote:
> I think incremental optimizations like this (which add complexity, and
> worse, beget more incremental optimizations) should be justified by data
> that shows that these cases are common enough to warrant such a thing.
>
>
> On 3/21/2018 3:00 PM, B. Blaser wrote:
>>
>> I note also that we may want to skip empty blocs '{}' and statements ';'.
>> The following examples would then produce only 2 lambda methods
>> instead of currently 8:
>>
>> Runnable r = () -> {};
>> r = () -> { ; };
>> r = () -> { {} };
>> r = () -> { { ; } };
>>
>> r = () -> { int i = 0; if (i==0) ; };
>> r = () -> { int i = 0; if (i==0) {} };
>> r = () -> { int i = 0; if (i==0) { ; } };
>> r = () -> { int i = 0; if (i==0) { {} } };
>>
>> I had to write a 'NoOpFinder' class (does something like that already
>> exist?) and I added a default action in 'TreeScanner' for that (see
>> below).
>>
>> Does this look reasonable (I did only some quick tests)?
>
>
More information about the amber-dev
mailing list