Re: [whatwg/encoding] TextEncoder#encode - write to existing Uint8Array (#69)

Sorry if I'm missing something obvious but how does the caller of `encodeInto` learn how many bytes were written into the BufferSource?

If this is indeed missing, one idea is: instead of returning a pair of numbers (which may add call overhead): what if the return value is the number of bytes written to the BufferSource and if less than the full `string` is written, an exception is thrown and the exception contains the (code-units-consumed, bytes-written) state.  Exceptions aren't super-cheap, but if we made them be non-[NativeError](https://tc39.github.io/ecma262/#sec-nativeerror) objects and if this is only coming up for relatively large strings, it might not be too bad when amortized?

Another comment is that, for Rust-to-JS-like use cases, each new `encodeInto` call will require creating a new view object, so being able to pass the `BufferSource` + bufferOffset + byteLength triple directly would avoid the costs of constructing, destructuring, and GCing these temporary view objects.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/issues/69#issuecomment-434423124

Received on Tuesday, 30 October 2018 18:54:01 UTC