On 07/11/2014 11:28 PM, Jeremy Manson wrote:
Hi Jaroslav,

I haven't written many Streams yet, so perhaps I'm missing something
obvious / well-known.  Streams can replace the original code in an
obvious way (filter the elements of list based on whether they are
contained in map.values()), but I'm not sure how the filter operation
becomes O(1) unless we build the HashSet?

Probably I should have been more explicit about this.

The map keys (a set) are derived from the map values by concatenating the method name with the method signature. Utilizing this you can then come up with a code like this:

return allMethods().stream()
         .filter((m) -> map.keySet().contains(getMethodTag(m)))
         .collect(Collectors.toList());

"getMethodTag(method)" is the function used to generate the hash key from a Method instance (to be extracted from the current source code).

But we would need a benchmark to figure out which construct actually performs better (the algorithmic complexity is the same).

-JB-


Jeremy


On Fri, Jul 11, 2014 at 3:11 AM, Jaroslav Bachorik
<jaroslav.bacho...@oracle.com <mailto:jaroslav.bacho...@oracle.com>> wrote:

    Hi Jeremy,


    On 05/08/2014 08:56 PM, Jeremy Manson wrote:

        I'm testing out my newly acquired OpenJDK authorship with something
        simple.  If I did this wrong, I apologize.

        Basically, the debugger becomes very slow if there are a lot of
        methods
        in a class.  This can happen (O(thousands)) if you are using a code
        generation tool.

        http://cr.openjdk.java.net/~__jmanson/8042778/webrev.00/
        <http://cr.openjdk.java.net/~jmanson/8042778/webrev.00/>


    Have you considered using streams to avoid creation of an additional
    HashSet?

    -JB-



        Reviews from reviewers and committing from committers would be
        appreciated.  Thanks!

        Jeremy




Reply via email to