On 11/02/2011 13:48, Steven Schveighoffer wrote:
On Fri, 11 Feb 2011 08:19:51 -0500, Bruno Medeiros
<brunodomedeiros+spam@com.gmail> wrote:

On 04/02/2011 21:07, Steven Schveighoffer wrote:
On Fri, 04 Feb 2011 15:44:46 -0500, Jeff Nowakowski <j...@dilacero.org>
wrote:

On 02/03/2011 10:07 PM, Walter Bright wrote:

The way to get a high performance string parser in D is to take
advantage of one of D's unique features - slices. Java, C++, C#, etc.,
all rely on copying strings. With D you can just use slices into the
original XML source text. If you're copying the text, you're doing it
wrong.

Java's substring() does not copy the text, at least in the official
JDK implementation. Unfortunately, it doesn't specify this behavior as
part of the String API.

Yes, but Java's strings are immutable. Typically a buffered I/O stream
has a mutable buffer used to read data. This necessitates a copy. At the
very least, you need to continue allocating more memory to hold all the
strings.

-Steve

True, but in this case you will have the exact same problem with any
other language as well. So it doesn't seem like D will have any
particular advantage over Java, with regards to slicing and strings.


I think D can do it without copying out of the buffer. You just have to
avoid using immutable strings.

-Steve

The data that you want to keep afterwards you will have to copy, that much is obvious. As for the data you don't want to keep (but just guide you through the parsing), yes in D you can look at it without copying it out of the buffer. But you can do the same in Java, there is this core interface CharSequence that is roughly equivalent to a D slice for chars (http://download.oracle.com/javase/1.4.2/docs/api/java/lang/CharSequence.html)

--
Bruno Medeiros - Software Engineer

Reply via email to