[Webkit-unassigned] [Bug 228122] Add functionalities for parsing URL query string

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Aug 2 18:29:45 PDT 2021


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

--- Comment #27 from Risul Islam <risul_islam 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;
>>     };
> 
> Wow, elegant code.

One issue found here. Had to write comparesLessThan like this: 
auto comparesLessThan = [&compare] (const KeyValuePair<String, String>& a, const KeyValuePair<String, String>& b) { return compare(a, b) < 0; };
Otherwise, it does not recognize 'compare'.

-- 
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/20210803/3010798d/attachment.htm>


More information about the webkit-unassigned mailing list