WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
123707
[Cocoa] Wrappers' -copyWithZone: should copy if the collection is mutable
https://bugs.webkit.org/show_bug.cgi?id=123707
Summary
[Cocoa] Wrappers' -copyWithZone: should copy if the collection is mutable
mitz
Reported
2013-11-03 10:35:49 PST
[Cocoa] Wrappers' -copyWithZone: should copy if the collection is mutable
Attachments
If the collection is mutable, make a copy
(2.65 KB, patch)
2013-11-03 10:38 PST
,
mitz
no flags
Details
Formatted Diff
Diff
If the collection is mutable, make a copy
(2.65 KB, patch)
2013-11-03 12:30 PST
,
mitz
ggaren
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
mitz
Comment 1
2013-11-03 10:38:16 PST
Created
attachment 215870
[details]
If the collection is mutable, make a copy
Geoffrey Garen
Comment 2
2013-11-03 12:25:33 PST
Comment on
attachment 215870
[details]
If the collection is mutable, make a copy View in context:
https://bugs.webkit.org/attachment.cgi?id=215870&action=review
> Source/WebKit2/Shared/ImmutableArray.h:68 > + const Vector<RefPtr<APIObject>> entries() { return m_entries; }
Should this be Vector& instead of Vector? As written, each call to entries() will make a copy.
> Source/WebKit2/Shared/Cocoa/WKNSArray.mm:63 > + auto entries = reinterpret_cast<ImmutableArray*>(&_array)->entries();
If you had not used auto in this context, you would have use an explicit reference type, in which case the compiler would have caught the extra copy mistake (assuming I am right that it was a mistake).
mitz
Comment 3
2013-11-03 12:28:32 PST
Comment on
attachment 215870
[details]
If the collection is mutable, make a copy View in context:
https://bugs.webkit.org/attachment.cgi?id=215870&action=review
>> Source/WebKit2/Shared/ImmutableArray.h:68 >> + const Vector<RefPtr<APIObject>> entries() { return m_entries; } > > Should this be Vector& instead of Vector? As written, each call to entries() will make a copy.
Yes.
>> Source/WebKit2/Shared/Cocoa/WKNSArray.mm:63 >> + auto entries = reinterpret_cast<ImmutableArray*>(&_array)->entries(); > > If you had not used auto in this context, you would have use an explicit reference type, in which case the compiler would have caught the extra copy mistake (assuming I am right that it was a mistake).
This needs to be a copy, not a reference.
mitz
Comment 4
2013-11-03 12:30:49 PST
Created
attachment 215872
[details]
If the collection is mutable, make a copy
Geoffrey Garen
Comment 5
2013-11-03 12:37:03 PST
Comment on
attachment 215872
[details]
If the collection is mutable, make a copy r=me
Geoffrey Garen
Comment 6
2013-11-03 12:38:55 PST
> >> Source/WebKit2/Shared/Cocoa/WKNSArray.mm:63 > >> + auto entries = reinterpret_cast<ImmutableArray*>(&_array)->entries(); > > > > If you had not used auto in this context, you would have use an explicit reference type, in which case the compiler would have caught the extra copy mistake (assuming I am right that it was a mistake). > > This needs to be a copy, not a reference.
What I meant was that, if you had used const ImmutableArray::VectorType& entries = ... you would have gotten an error, due to taking a reference to a temporary, which might have alerted you to the accidental copy caused by the return type of entries(). I think about stuff like this because I'm still not sure when we should use auto, and when we should not.
mitz
Comment 7
2013-11-03 12:41:13 PST
(In reply to
comment #6
)
> > >> Source/WebKit2/Shared/Cocoa/WKNSArray.mm:63 > > >> + auto entries = reinterpret_cast<ImmutableArray*>(&_array)->entries(); > > > > > > If you had not used auto in this context, you would have use an explicit reference type, in which case the compiler would have caught the extra copy mistake (assuming I am right that it was a mistake). > > > > This needs to be a copy, not a reference. > > What I meant was that, if you had used > > const ImmutableArray::VectorType& entries = ... > > you would have gotten an error, due to taking a reference to a temporary, which might have alerted you to the accidental copy caused by the return type of entries().
But, regardless of my mistake in the definition of entries(), I wouldn’t have used the above type for the local, since I did want a copy, not a reference.
mitz
Comment 8
2013-11-03 12:41:27 PST
Committed <
http://trac.webkit.org/r158538
>.
Geoffrey Garen
Comment 9
2013-11-03 12:48:42 PST
> But, regardless of my mistake in the definition of entries(), I wouldn’t have used the above type for the local, since I did want a copy, not a reference.
Uh oh. Since the patch you committed passes a reference from _array (and _dictionary) to adopt(), and adopt() calls swap() -- does this mean that -copyWithZone will remove all entries from self? I am demonstrating my limitations as a reviewer :(.
mitz
Comment 10
2013-11-03 12:56:25 PST
(In reply to
comment #9
)
> > But, regardless of my mistake in the definition of entries(), I wouldn’t have used the above type for the local, since I did want a copy, not a reference. > > Uh oh. Since the patch you committed passes a reference from _array (and _dictionary) to adopt(), and adopt() calls swap() -- does this mean that -copyWithZone will remove all entries from self?
The locals’ types aren’t const references. They are a Vector and a MapType.
mitz
Comment 11
2013-11-03 18:57:26 PST
(In reply to
comment #8
)
> Committed <
http://trac.webkit.org/r158538
>.
I shouldn’t have landed this patch without a WebKit2 owner’s permission. I reverted the change in <
http://trac.webkit.org/r158552
>.
mitz
Comment 12
2013-11-03 18:59:34 PST
…and committed <
http://trac.webkit.org/r158553
>.
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