Bug 109864 - No easy way to use a RetainPtr as a key in a HashMap using object (rather than pointer) equality
Summary: No easy way to use a RetainPtr as a key in a HashMap using object (rather tha...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: mitz
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-14 14:28 PST by mitz
Modified: 2013-02-14 14:59 PST (History)
3 users (show)

See Also:


Attachments
Patch (2.47 KB, patch)
2013-02-14 14:30 PST, mitz
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mitz 2013-02-14 14:28:04 PST
A HashMap<RetainPtr<NSObject>, ValueType> uses pointer hashing and pointer equality rather than -hash and -isEqual:.
Comment 1 mitz 2013-02-14 14:30:14 PST
Created attachment 188429 [details]
Patch
Comment 2 Benjamin Poulain 2013-02-14 14:40:48 PST
View in context: https://bugs.webkit.org/attachment.cgi?id=188429&action=review

> Source/WTF/wtf/RetainPtr.h:310
> +        static void constructDeletedValue(RetainPtr<P>& slot) { new (&slot) RetainPtr<P>(AdoptCF, reinterpret_cast<P *>(-1)); }
> +        static bool isDeletedValue(const RetainPtr<P>& value) { return value.get() == reinterpret_cast<P *>(-1); }

I would prefer something using an explicit constructor, like we do in RefPtr.
Comment 3 mitz 2013-02-14 14:59:45 PST
(In reply to comment #2)
> View in context: https://bugs.webkit.org/attachment.cgi?id=188429&action=review
> 
> > Source/WTF/wtf/RetainPtr.h:310
> > +        static void constructDeletedValue(RetainPtr<P>& slot) { new (&slot) RetainPtr<P>(AdoptCF, reinterpret_cast<P *>(-1)); }
> > +        static bool isDeletedValue(const RetainPtr<P>& value) { return value.get() == reinterpret_cast<P *>(-1); }
> 
> I would prefer something using an explicit constructor, like we do in RefPtr.

Done!

Fixed in <http://trac.webkit.org/r142924>.