[Webkit-unassigned] [Bug 228122] Add functionalities for parsing URL query string
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon Aug 2 11:15:44 PDT 2021
https://bugs.webkit.org/show_bug.cgi?id=228122
--- Comment #25 from Darin Adler <darin at apple.com> ---
Comment on attachment 434736
--> https://bugs.webkit.org/attachment.cgi?id=434736
Patch
View in context: https://bugs.webkit.org/attachment.cgi?id=434736&action=review
>> Source/WTF/wtf/URL.cpp:1189
>> + return firstKeyValuePairAppended.toString().utf8() < secondKeyValuePairAppended.toString().utf8();
>
> 1) There is no reason to repeat this lambda twice! We can put it in a local variable and use it twice. Also, we repeat the comparison below, and should reuse for that too.
>
> 2) Concatenating strings using StringBuilder, then converting to UTF-8 is a super-expensive way to compare and makes this unnecessarily inefficient. Seems unlikely the sorting order matters at all:
>
> Code should be more like this:
>
> auto compare = [&] (const KeyValuePair<String, String>& a, const KeyValuePair<String, String>& b) {
> if (int result = codePointCompare(a.key, b.key))
> return result;
> return codePointCompare(a.value, b.value);
> };
> auto comparesLessThan = [&] (const KeyValuePair<String, String>& a, const KeyValuePair<String, String>& b) {
> return compare(a, b) < 0;
> };
>
> std::sort(firstQueryParameters.begin(), firstQueryParameters.end(), comparesLessThan);
> std::sort(secondQueryParameters.begin(), secondQueryParameters.end(), comparesLessThan);
By the way, the capture here is wrong. This would be better:
auto compare = [] (const KeyValuePair<String, String>& a, const KeyValuePair<String, String>& b)
{
if (int result = codePointCompare(a.key, b.key))
return result;
return codePointCompare(a.value, b.value);
};
auto comparesLessThan = [] (const KeyValuePair<String, String>& a, const KeyValuePair<String, String>& b)
{
return compare(a, b) < 0;
};
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20210802/0f835e34/attachment.htm>
More information about the webkit-unassigned
mailing list