You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/25 15:56:00 UTC

[jira] [Resolved] (GROOVY-8004) CompileStatic ImmutableList.size() calls DefaultGroovyMethods.size(Iterable)

     [ https://issues.apache.org/jira/browse/GROOVY-8004?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-8004.
---------------------------------
    Resolution: Fixed

> CompileStatic ImmutableList.size() calls DefaultGroovyMethods.size(Iterable)
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-8004
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8004
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.7
>            Reporter: Jan Kanis
>            Assignee: Eric Milles
>            Priority: Major
>
> Calling {{size()}} on a Guava ImmutableList (which implements {{List}}) under {{@CompileStatic}} calls DefaultGroovyMethods.size(Iterable) instead ImmutableList.size(). If the variable is of type {{List}} and the compiler cannot deduce that it actually contains an {{ImmutableList}} the {{List.size()}} method is called as expected.
> The same bug exists for general Guava collections. 
> Obviously this is bad especially for large collections, where a {{size()}} ends up taking linear time instead of constant time.
> Example:
> {code}
> import com.google.common.collect.ImmutableList
> import groovy.transform.CompileStatic
> @CompileStatic
> class TestClass {
>     public static void main(String[] args) {
>         ImmutableList<String> l = ImmutableList.copyOf(args)
>         List<String> ls = l as List
>         println(l.size()) // Calls DefaultGroovyMethods.size(Iterable)
>         println(ls.size()) // Calls List.size()
>     }
> }
> {code}
> View the generated code with {{javap -p -c TestClass.class}} to see the calls that were emitted.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)