Timeline for Making ArrayList.containsAll run faster
Current License: CC BY-SA 3.0
3 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 5, 2015 at 15:53 | comment | added | Emily L. |
@maaartinus What you're saying doesn't contradict my post at all. I'm not saying that String#hashCode itself is slow. I'm saying that OP's implementation has to calculate the hash code for every object in the argument container. Which is slow where ArrayList#containsAll can exit early. What I'm saying is that OP isn't seeing this behavior because the hashCode function of Integer is trivial.
|
|
Jul 5, 2015 at 14:22 | comment | added | maaartinus |
You're actually pretty wrong. The reason for the slowness is not the slow String#hashCode . It can't be as it gets computed just once and cached then. The slowness comes from the fact that that ArrayList#containsAll exits quickly when the first non-contained string gets found while MyArrayList#containsAll wastes time with the HashMap creation. +++ Another problem is that OP's method computes something else, namely coll.containsAll(this) .
|
|
Jul 5, 2015 at 10:30 | history | answered | Emily L. | CC BY-SA 3.0 |