[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] String support in DataView

On Fri, Nov 4, 2011 at 5:36 PM, Glenn Maynard <glenn@zewt.org> wrote:
> int len = StringEncoding.stringLength(array3);
> var s3 = StringEncoding.decode(array3, 0, len);

There will be an objection raised that this requires decoding twice. (The reason for the outstanding "partial fill" issue is that there are objections to having encode twice, once to determine length and a second time to fill the buffer.) I like this proposal, though.

It doesn't need to decode twice; it only needs to pass over the data twice (strnlen or wcsnlen, effectively), which is much cheaper and easily optimized than a full decode.

For most encodings, you are saving at most a single shift over actually doing the decoding (plus of course whatever work is involved in doing something with the decoded value), so I am not sure I buy this is fundamentally cheaper.
FYI, the two fundamental differences between Blob and ArrayBuffer are that Blob is asynchronous (in order to allow very large blocks of data, which may be swapped to disk), and immutable. ArrayBuffer is synchronous, which is more convenient but can't scratch data to disk, and mutable.

So it would seem that having to convert data to a Blob in order to use its character encoding support would mean giving up all the reasons that ArrayBuffer exists in the first place, right?

John A. Tamplin
Software Engineer (GWT), Google