WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
139971
Convert OwnPtr to std::unique_ptr in WebCore/graphics/
https://bugs.webkit.org/show_bug.cgi?id=139971
Summary
Convert OwnPtr to std::unique_ptr in WebCore/graphics/
Gyuyoung Kim
Reported
2014-12-28 02:13:58 PST
SSIA
Attachments
Patch
(21.56 KB, patch)
2014-12-28 02:18 PST
,
Gyuyoung Kim
no flags
Details
Formatted Diff
Diff
Patch
(21.57 KB, patch)
2014-12-28 06:26 PST
,
Gyuyoung Kim
no flags
Details
Formatted Diff
Diff
Patch
(23.61 KB, patch)
2014-12-28 20:19 PST
,
Gyuyoung Kim
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Gyuyoung Kim
Comment 1
2014-12-28 02:18:49 PST
Created
attachment 243780
[details]
Patch
Gyuyoung Kim
Comment 2
2014-12-28 06:26:08 PST
Created
attachment 243781
[details]
Patch
Darin Adler
Comment 3
2014-12-28 11:05:26 PST
Comment on
attachment 243781
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=243781&action=review
> Source/WebCore/platform/graphics/GlyphMetricsMap.h:114 > return page; > } else > - m_pages = adoptPtr(new HashMap<int, OwnPtr<GlyphMetricsPage>>); > + m_pages = std::make_unique<HashMap<int, std::unique_ptr<GlyphMetricsPage>>>(); > page = new GlyphMetricsPage; > - m_pages->set(pageNumber, adoptPtr(page)); > + m_pages->set(pageNumber, std::unique_ptr<GlyphMetricsPage>(page));
We are really trying to avoid this idiom where we adopt by invoking the std::unique_ptr constructor. This function also does double hash table lookup and it need not do that. I suggest this code instead: if (!m_pages) m_pages = std::make_unique<HashMap<int, std::unique_ptr<GlyphMetricsPage>>>(); auto& pageInMap = m_pages->add(pageNumber, nullptr).iterator->value; if (!pageInMap) pageInMap = std::make_unique<GlyphMetricsPage>(); page = pageInMap; This will set up the page in the map with only a single hash table lookup.
> Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp:345 > + m_children.set(fontData, std::unique_ptr<GlyphPageTreeNode>(child));
Again, this is not the idiom we want. Instead we should put the GlyphPageTreeNode into a local variable that is already a unique_ptr. One way to do this would be to have both a unique_ptr and a raw pointer pointing at the same thing. But even better, it’s possible to rearrange this function so it won’t have a raw pointer and also eliminate the double hashing it does. We would figure out where the child goes right at the start, replacing the "foundChild" code. auto& child = fontData ? m_children.add(fontData, nullptr).iterator->value : m_systemFallbackChild; if (child) return child.get(); child = std::make_unique<GlyphPageTreeNode>(); ... return child.get(); The other code in the function would stay the same.
> Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h:40 > + explicit Extensions3DOpenGL(GraphicsContext3D*);
This argument should really be a reference rather than a pointer. But no need to change it right now.
> Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h:61 > // This class only needs to be instantiated by GraphicsContext3D implementations.
I don’t think this comment makes sense any more.
> Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h:62 > friend class GraphicsContext3D;
I don’t think this line of code is helpful any more.
Darin Adler
Comment 4
2014-12-28 11:06:22 PST
Comment on
attachment 243781
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=243781&action=review
>> Source/WebCore/platform/graphics/opengl/Extensions3DOpenGL.h:61 >> // This class only needs to be instantiated by GraphicsContext3D implementations. > > I don’t think this comment makes sense any more.
The comment *might* have some value, but it belongs up at the constructor, I think.
Gyuyoung Kim
Comment 5
2014-12-28 20:19:03 PST
Created
attachment 243788
[details]
Patch
Gyuyoung Kim
Comment 6
2014-12-28 20:19:26 PST
Comment on
attachment 243781
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=243781&action=review
>> Source/WebCore/platform/graphics/GlyphMetricsMap.h:114 >> + m_pages->set(pageNumber, std::unique_ptr<GlyphMetricsPage>(page)); > > We are really trying to avoid this idiom where we adopt by invoking the std::unique_ptr constructor. This function also does double hash table lookup and it need not do that. I suggest this code instead: > > if (!m_pages) > m_pages = std::make_unique<HashMap<int, std::unique_ptr<GlyphMetricsPage>>>(); > auto& pageInMap = m_pages->add(pageNumber, nullptr).iterator->value; > if (!pageInMap) > pageInMap = std::make_unique<GlyphMetricsPage>(); > page = pageInMap; > > This will set up the page in the map with only a single hash table lookup.
Thank you for your suggestion. New patch uses this code.
>> Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp:345 >> + m_children.set(fontData, std::unique_ptr<GlyphPageTreeNode>(child)); > > Again, this is not the idiom we want. Instead we should put the GlyphPageTreeNode into a local variable that is already a unique_ptr. > > One way to do this would be to have both a unique_ptr and a raw pointer pointing at the same thing. > > But even better, it’s possible to rearrange this function so it won’t have a raw pointer and also eliminate the double hashing it does. We would figure out where the child goes right at the start, replacing the "foundChild" code. > > auto& child = fontData ? m_children.add(fontData, nullptr).iterator->value : m_systemFallbackChild; > if (child) > return child.get(); > > child = std::make_unique<GlyphPageTreeNode>(); > > ... > > return child.get(); > > The other code in the function would stay the same.
I try to apply your second suggestion to new patch. Thanks.
WebKit Commit Bot
Comment 7
2014-12-28 22:24:48 PST
Comment on
attachment 243788
[details]
Patch Clearing flags on attachment: 243788 Committed
r177786
: <
http://trac.webkit.org/changeset/177786
>
WebKit Commit Bot
Comment 8
2014-12-28 22:24:53 PST
All reviewed patches have been landed. Closing bug.
Gyuyoung Kim
Comment 9
2014-12-29 00:19:49 PST
This commit made a build break on win port. I landed two fixes for win port though, second fix is not tested on win bot yet.
https://trac.webkit.org/changeset/177787
https://trac.webkit.org/changeset/177788
Chris Dumez
Comment 10
2016-05-16 13:22:44 PDT
Comment on
attachment 243788
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=243788&action=review
> Source/WebCore/platform/graphics/GlyphMetricsMap.h:-110 > - return page;
Previously, there was an early return here, which meant that we would only do the for loop below (the one initializing the page with unknown metrics) if the page is new. After your change, we always fill the page with unknown metrics, even if it is an existing page :/ I will fix.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug