Bug 150022 - Add helper function for checking pointer equivalency and use it
Summary: Add helper function for checking pointer equivalency and use it
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-11 21:47 PDT by Simon Fraser (smfr)
Modified: 2015-10-13 17:15 PDT (History)
13 users (show)

See Also:


Attachments
Patch (31.18 KB, patch)
2015-10-11 21:57 PDT, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Patch (36.23 KB, patch)
2015-10-12 22:12 PDT, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Patch (37.73 KB, patch)
2015-10-12 22:56 PDT, Simon Fraser (smfr)
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2015-10-11 21:47:35 PDT
Add helper funtion for checking pointer equivalency and use it
Comment 1 Simon Fraser (smfr) 2015-10-11 21:57:25 PDT
Created attachment 262877 [details]
Patch
Comment 2 Simon Fraser (smfr) 2015-10-11 21:58:21 PDT
Not sure if RefPtr.h is the best place for bool areEquivalent(const T* a, const T* b), and it would be nice to have a unique_ptr version. Where to put it?
Comment 3 Alexey Proskuryakov 2015-10-11 23:17:51 PDT
Comment on attachment 262877 [details]
Patch

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

> Source/WTF/ChangeLog:3
> +        Add helper funtion for checking pointer equivalency and use it

Where does this use of the word "equivalency" originate from? I'm not familiar with it, and it looks quite misleading to me.
Comment 4 Simon Fraser (smfr) 2015-10-12 08:14:40 PDT
It was used in the style code quite a bit:
-        && shadowDataEquivalent(o)
-        && willChangeDataEquivalent(o)
-        && reflectionDataEquivalent(o)
-        && animationDataEquivalent(o)
-        && transitionDataEquivalent(o)
+        && areEquivalent(m_counterDirectives.get(), o.m_counterDirectives.get())
+        && areEquivalent(m_boxShadow.get(), o.m_boxShadow.get())
+        && areEquivalent(m_willChange, o.m_willChange)
+        && areEquivalent(m_boxReflect, o.m_boxReflect)
+        && areEquivalent(m_animations.get(), o.m_animations.get())
+        && areEquivalent(m_transitions.get(), o.m_transitions.get())
Comment 5 Darin Adler 2015-10-12 16:59:52 PDT
Comment on attachment 262877 [details]
Patch

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

> Source/WTF/wtf/RefPtr.h:223
> +template<typename T> inline bool areEquivalent(const T* a, const T* b)
> +{ 
> +    return a == b || (a && b && *a == *b);
> +}

Should just implement this for all types instead of just pointers:

    template<typename T> inline bool areEquivalent(const T& a, const T& b)
    { 
        return a == b || (a && b && *a == *b);
    }

Then you don’t need a RefPtr overload. I suggest putting this somewhere in the WebCore tree instead of in WTF and naming it something more like isPointedToDataEqual.
Comment 6 Simon Fraser (smfr) 2015-10-12 17:03:52 PDT
I'm not sure I can handle that singular use of data :)
Comment 7 Simon Fraser (smfr) 2015-10-12 18:11:28 PDT
We like arePointingToEqualData().
Comment 8 Simon Fraser (smfr) 2015-10-12 22:12:05 PDT
Created attachment 262971 [details]
Patch
Comment 9 Simon Fraser (smfr) 2015-10-12 22:13:00 PDT
I put it in WTF because there's place in WebCore for shared, non-platform-specific utilities, and we may want to use it in JSC or WebKit.
Comment 10 Simon Fraser (smfr) 2015-10-12 22:56:11 PDT
Created attachment 262973 [details]
Patch
Comment 11 Darin Adler 2015-10-13 09:27:12 PDT
Comment on attachment 262973 [details]
Patch

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

> Source/WebCore/rendering/style/FillLayer.cpp:157
> +    return arePointingToEqualData(m_image.get(), o.m_image.get()) && m_xPosition == o.m_xPosition && m_yPosition == o.m_yPosition

I believe there is no need for the .get() here since arePointingToEqualData works on smart pointers too, not just raw pointers.

> Source/WebCore/rendering/style/RenderStyle.cpp:559
> -        if (rareNonInheritedData->m_grid.get() != other.rareNonInheritedData->m_grid.get()
> -            || rareNonInheritedData->m_gridItem.get() != other.rareNonInheritedData->m_gridItem.get())
> +        if (rareNonInheritedData->m_grid != other.rareNonInheritedData->m_grid
> +            || rareNonInheritedData->m_gridItem != other.rareNonInheritedData->m_gridItem)

Too bad we don’t have test cases for this bug fix.

> Source/WebCore/rendering/style/RenderStyle.cpp:943
> +    if (arePointingToEqualData(rareNonInheritedData->m_willChange.get(), willChangeData.get()))

I believe there is no need for the .get() here since arePointingToEqualData works on smart pointers too, not just raw pointers.
Comment 12 Simon Fraser (smfr) 2015-10-13 09:34:32 PDT
(In reply to comment #11)
> Comment on attachment 262973 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=262973&action=review
> 
> > Source/WebCore/rendering/style/FillLayer.cpp:157
> > +    return arePointingToEqualData(m_image.get(), o.m_image.get()) && m_xPosition == o.m_xPosition && m_yPosition == o.m_yPosition
> 
> I believe there is no need for the .get() here since arePointingToEqualData
> works on smart pointers too, not just raw pointers.

I'll fix.

> > Source/WebCore/rendering/style/RenderStyle.cpp:559
> > -        if (rareNonInheritedData->m_grid.get() != other.rareNonInheritedData->m_grid.get()
> > -            || rareNonInheritedData->m_gridItem.get() != other.rareNonInheritedData->m_gridItem.get())
> > +        if (rareNonInheritedData->m_grid != other.rareNonInheritedData->m_grid
> > +            || rareNonInheritedData->m_gridItem != other.rareNonInheritedData->m_gridItem)
> 
> Too bad we don’t have test cases for this bug fix.

Yes!

> > Source/WebCore/rendering/style/RenderStyle.cpp:943
> > +    if (arePointingToEqualData(rareNonInheritedData->m_willChange.get(), willChangeData.get()))
> 
> I believe there is no need for the .get() here since arePointingToEqualData
> works on smart pointers too, not just raw pointers.

These are different types (PassRefPtr vs RefPtr), so the .get() are needed to turn both into raw pointers.
Comment 13 Simon Fraser (smfr) 2015-10-13 17:15:36 PDT
https://trac.webkit.org/r191017