Bug 109864

Summary: No easy way to use a RetainPtr as a key in a HashMap using object (rather than pointer) equality
Product: WebKit Reporter: mitz
Component: Web Template FrameworkAssignee: mitz
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, benjamin, jberlin
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch sam: review+

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>.