3 ms·
Not an answer, but an additional argument for making this stack only: it avoids the problem Java's substring operator had. It used to be O(1), with the resultin
by Someone 10y ago
Not an answer, but an additional argument for making this stack only: it avoids the problem Java's substring operator had. It used to be O(1), with the resulting string sharing its data buffer with the underlying string.
Problem with that is that a small substring of a larger string prevents the data buffer of the larger string to be garbage collected.
That happened a lot when parsing files. Let's say you read a 1 GB, 10M row cvs file with a small string ID and 10 integers on each line. The strings should take maybe 100MB, but they will take 1GB. Oops.
The behaviour of the substring function changed to copy string data in JDK7 (after quite a bit of deliberation. There was a nice writeup of the results somewhere, but I can't find it)