[webkit-reviews] review granted: [Bug 193274] Implement TextEncoder's encodeInto() : [Attachment 407853] Patch
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Sep 2 20:51:50 PDT 2020
Darin Adler <darin at apple.com> has granted Alex Christensen
<achristensen at apple.com>'s request for review:
Bug 193274: Implement TextEncoder's encodeInto()
https://bugs.webkit.org/show_bug.cgi?id=193274
Attachment 407853: Patch
https://bugs.webkit.org/attachment.cgi?id=407853&action=review
--- Comment #2 from Darin Adler <darin at apple.com> ---
Comment on attachment 407853
--> https://bugs.webkit.org/attachment.cgi?id=407853
Patch
View in context: https://bugs.webkit.org/attachment.cgi?id=407853&action=review
> Source/WebCore/dom/TextEncoder.cpp:64
> + uint8_t buffer[U8_MAX_LENGTH];
> + unsigned offset = 0;
> + U8_APPEND(buffer, offset, sizeof(buffer), token, sawError);
> + if (sawError)
> + break;
> + if (written + offset > capacity)
> + break;
> + memcpy(destinationBytes + written, buffer, offset);
> + written += offset;
Since U8_APPEND has bounds checking built in we don’t need to keep using a
buffer every time. We could do something more like this:
auto offset = written;
U8_APPEND(destinationBytes, offset, capacity, token, sawError);
if (sawError)
break;
written = offset;
> Source/WebCore/dom/TextEncoder.cpp:68
> + if (U_IS_BMP(token))
> + read++;
> + else
> + read += 2;
This could be:
read += U16_LENGTH(token);
More information about the webkit-reviews
mailing list