Bug 136212 - [TexMap] Use std::sort instead of qsort in TextureMapperLayer::sortByZOrder()
Summary: [TexMap] Use std::sort instead of qsort in TextureMapperLayer::sortByZOrder()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Zan Dobersek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-25 02:48 PDT by Zan Dobersek
Modified: 2015-01-07 05:19 PST (History)
8 users (show)

See Also:


Attachments
Patch (3.12 KB, patch)
2014-08-25 02:54 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff
Patch (3.11 KB, patch)
2015-01-06 11:05 PST, Zan Dobersek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2014-08-25 02:48:38 PDT
[TexMap] Use std::sort instead of qsort in TextureMapperLayer::sortByZOrder()
Comment 1 Zan Dobersek 2014-08-25 02:54:23 PDT
Created attachment 237069 [details]
Patch
Comment 2 WebKit Commit Bot 2014-08-25 02:55:51 PDT
Attachment 237069 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:156:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Sergio Villar Senin 2014-08-25 03:12:04 PDT
Comment on attachment 237069 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=237069&action=review

> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:157
> +            return a->m_centerZ < b->m_centerZ * 1000;

why "* 1000" ?
Comment 4 Brent Fulgham 2014-10-31 12:37:25 PDT
It's not clear from this bug why the change is being proposed. Do you find that std::sort is quicker than qsort, or has better memory characteristics?

Could you include that in the ChangeLog to give context?
Comment 5 Brent Fulgham 2014-10-31 12:38:12 PDT
Comment on attachment 237069 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=237069&action=review

>> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:157
>> +            return a->m_centerZ < b->m_centerZ * 1000;
> 
> why "* 1000" ?

That's the same as was used in the original compareGraphicsLayerZValue method.
Comment 6 Zan Dobersek 2014-11-02 02:57:55 PST
(In reply to comment #4)
> It's not clear from this bug why the change is being proposed. Do you find
> that std::sort is quicker than qsort, or has better memory characteristics?
> 
> Could you include that in the ChangeLog to give context?

std::sort() can be faster due to ideally inlining the comparison function.

There are a couple of issues with rendering when std::sort() is used instead of qsort. I'll look into that first and then update the patch.
Comment 7 Zan Dobersek 2014-11-02 03:02:38 PST
Comment on attachment 237069 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=237069&action=review

>>> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:157
>>> +            return a->m_centerZ < b->m_centerZ * 1000;
>> 
>> why "* 1000" ?
> 
> That's the same as was used in the original compareGraphicsLayerZValue method.

I kept the same comparison that was used for qsort. But I don't know off the top of my head why 1000 is used here.
Comment 8 Darin Adler 2014-12-27 13:36:47 PST
Comment on attachment 237069 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=237069&action=review

>>>> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:157
>>>> +            return a->m_centerZ < b->m_centerZ * 1000;
>>> 
>>> why "* 1000" ?
>> 
>> That's the same as was used in the original compareGraphicsLayerZValue method.
> 
> I kept the same comparison that was used for qsort. But I don't know off the top of my head why 1000 is used here.

That * 1000 is absolutely *not* the same as what was in the original function!

The original subtracts two floats and then multiplies the difference times 1000 to convert them to an integer that the sort algorithm can use. Look carefully at where the parentheses are.

This new code multiplies only b’s value by 1000. That’s not right.
Comment 9 Zan Dobersek 2015-01-05 03:26:07 PST
Comment on attachment 237069 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=237069&action=review

>>>>> Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:157
>>>>> +            return a->m_centerZ < b->m_centerZ * 1000;
>>>> 
>>>> why "* 1000" ?
>>> 
>>> That's the same as was used in the original compareGraphicsLayerZValue method.
>> 
>> I kept the same comparison that was used for qsort. But I don't know off the top of my head why 1000 is used here.
> 
> That * 1000 is absolutely *not* the same as what was in the original function!
> 
> The original subtracts two floats and then multiplies the difference times 1000 to convert them to an integer that the sort algorithm can use. Look carefully at where the parentheses are.
> 
> This new code multiplies only b’s value by 1000. That’s not right.

Well, that turned out embarrassing.

Thanks for spotting it.
Comment 10 Zan Dobersek 2015-01-06 11:05:59 PST
Created attachment 244075 [details]
Patch
Comment 11 WebKit Commit Bot 2015-01-06 11:08:56 PST
Attachment 244075 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:156:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 Zan Dobersek 2015-01-07 05:19:19 PST
Comment on attachment 244075 [details]
Patch

Clearing flags on attachment: 244075

Committed r178035: <http://trac.webkit.org/changeset/178035>
Comment 13 Zan Dobersek 2015-01-07 05:19:28 PST
All reviewed patches have been landed.  Closing bug.