[Webkit-unassigned] [Bug 33222] Make text decoders and resource loaders read from segmented SharedBuffer

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jan 5 12:17:40 PST 2010


https://bugs.webkit.org/show_bug.cgi?id=33222





--- Comment #4 from Darin Adler <darin at apple.com>  2010-01-05 12:17:40 PST ---
(From update of attachment 45914)
> -    String sheetText = m_decoder->decode(m_data->data(), m_data->size());
> +    String sheetText;
> +    const char* segment;
> +    unsigned pos = 0;

Could you avoid the abbreviation "pos" here? I like "offset" for this, myself.

> +    while (unsigned length = m_data->getSomeData(segment, pos)) {

It's unfortunate this operation is O(n log n) in the number of segments, having
to find the data segment each time based on the passed-in offset, walking the
list of segments. I wish the API of SharedBuffer didn't force this, although
it's probably not a real concern.

Rather than repeating this decoding idiom over and over again, could you put a
helper function somewhere that encapsulates the process of decoding a
SharedBuffer into a String.

Appending to a String is a slow operation that requires reallocating the buffer
each time. Instead we should append to a Vector<UChar> and convert to a String
only at the end. Making a single function for this will help us make sure it
works in a way that's optimal.

Another good optimization would be estimating the decoded size based on the
size of the SharedBuffer to keep the number of reallocations to a minimum. This
should be straightforward. We could start by assuming that each byte encodes an
average of about one character.


> -            loader->didReceiveData(data->data(), data->size(), data->size(), true);
> +            const char* segment;
> +            unsigned pos = 0;
> +            int received = 0;
> +            while (unsigned length = data->getSomeData(segment, pos)) {
> +                pos += length;
> +                loader->didReceiveData(segment, length, pos, false);
> +            }

After this patch, is there any code anywhere passing true for the last argument
to didReceiveData? If not, then we should remove that argument and the dead
code.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list