Skip to content

Commit e33bfb3

Browse files
committed
8263450: Simplify LambdaForm.useCount
Reviewed-by: rriggs
1 parent 75ef6f5 commit e33bfb3

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/java.base/share/classes/java/lang/invoke/LambdaForm.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,10 +1598,13 @@ int lastUseIndex(Name n) {
15981598
* Return 0 if the name is not used.
15991599
*/
16001600
int useCount(Name n) {
1601-
if (arguments == null) return 0;
16021601
int count = 0;
1603-
for (int i = arguments.length; --i >= 0; ) {
1604-
if (arguments[i] == n) ++count;
1602+
if (arguments != null) {
1603+
for (Object argument : arguments) {
1604+
if (argument == n) {
1605+
count++;
1606+
}
1607+
}
16051608
}
16061609
return count;
16071610
}
@@ -1649,15 +1652,10 @@ int lastUseIndex(Name n) {
16491652

16501653
/** Return the number of times n is used as an argument or return value. */
16511654
int useCount(Name n) {
1652-
int nmax = names.length;
1653-
int end = lastUseIndex(n);
1654-
if (end < 0) return 0;
1655-
int count = 0;
1656-
if (end == nmax) { count++; end--; }
1657-
int beg = n.index() + 1;
1658-
if (beg < arity) beg = arity;
1659-
for (int i = beg; i <= end; i++) {
1660-
count += names[i].useCount(n);
1655+
int count = (result == n.index) ? 1 : 0;
1656+
int i = Math.max(n.index + 1, arity);
1657+
while (i < names.length) {
1658+
count += names[i++].useCount(n);
16611659
}
16621660
return count;
16631661
}

0 commit comments

Comments
 (0)