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

> For the length argument to Uint8Array, shouldn't bufferStart also be subtracted? (I also changed offset = read to offset += read. Better names welcome.)

No, I think it is okay as is.

Suppose `malloc()` returns 1000. Then the first call to the constructor will be `new Uint8Array(buffer, 1000 + 0, 256 - 0)`. Assume that all 256 bytes were used, and `realloc()` returns 1000 again. Then the second call to the constructor will be `new Uint8Array(buffer, 1000 + 256, 512 - 256)`. This all looks good.

I realised that I wrote `bytesStart` in the constructor arguments where it should have been `bufferStart`.

Maybe `offset` would be clearer if it was called `readOffset`? Possibly `bytesWritten` could be changed to `writeOffset` to match.

-- 
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-447581178

Received on Saturday, 15 December 2018 16:41:47 UTC