Use HashMap<OwnPtr> in CrossOriginPreflightResultCache
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 02:55:47 +0000 (02:55 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 02:55:47 +0000 (02:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73785

Reviewed by Andreas Kling.

* loader/CrossOriginPreflightResultCache.cpp:
(WebCore::CrossOriginPreflightResultCache::appendEntry): Changed code to use set
instead of add, since it wants to replace existing entries. Also removed leakPtr
and removed the FIXME that documented the memory leak now fixed here.
(WebCore::CrossOriginPreflightResultCache::canSkipPreflight): Removed unneeded
std:: prefix here and also unneeded explicit delete call.
(WebCore::CrossOriginPreflightResultCache::empty): Removed unneeded deleteAllValues
call here.

* loader/CrossOriginPreflightResultCache.h: Make mapped value of the
CrossOriginPreflightResultHashMap be OwnPtr instead of raw pointer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/CrossOriginPreflightResultCache.cpp
Source/WebCore/loader/CrossOriginPreflightResultCache.h

index f7f88c1..b6b956e 100644 (file)
@@ -1,5 +1,24 @@
 2011-12-05  Darin Adler  <darin@apple.com>
 
+        Use HashMap<OwnPtr> in CrossOriginPreflightResultCache
+        https://bugs.webkit.org/show_bug.cgi?id=73785
+
+        Reviewed by Andreas Kling.
+
+        * loader/CrossOriginPreflightResultCache.cpp:
+        (WebCore::CrossOriginPreflightResultCache::appendEntry): Changed code to use set
+        instead of add, since it wants to replace existing entries. Also removed leakPtr
+        and removed the FIXME that documented the memory leak now fixed here.
+        (WebCore::CrossOriginPreflightResultCache::canSkipPreflight): Removed unneeded
+        std:: prefix here and also unneeded explicit delete call.
+        (WebCore::CrossOriginPreflightResultCache::empty): Removed unneeded deleteAllValues
+        call here.
+
+        * loader/CrossOriginPreflightResultCache.h: Make mapped value of the
+        CrossOriginPreflightResultHashMap be OwnPtr instead of raw pointer.
+
+2011-12-05  Darin Adler  <darin@apple.com>
+
         Some small improvements to ContainerNode.h
         https://bugs.webkit.org/show_bug.cgi?id=73786
 
index 1f0e712..198ddaf 100644 (file)
@@ -159,25 +159,19 @@ CrossOriginPreflightResultCache& CrossOriginPreflightResultCache::shared()
 void CrossOriginPreflightResultCache::appendEntry(const String& origin, const KURL& url, PassOwnPtr<CrossOriginPreflightResultCacheItem> preflightResult)
 {
     ASSERT(isMainThread());
-    CrossOriginPreflightResultCacheItem* resultPtr = preflightResult.leakPtr();
-    pair<CrossOriginPreflightResultHashMap::iterator, bool> addResult = m_preflightHashMap.add(make_pair(origin, url), resultPtr);
-    if (!addResult.second) {
-        // FIXME: We need to delete the old value before replacing with the new one.
-        addResult.first->second = resultPtr;
-    }
+    m_preflightHashMap.set(make_pair(origin, url), preflightResult);
 }
 
 bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, const KURL& url, StoredCredentials includeCredentials, const String& method, const HTTPHeaderMap& requestHeaders)
 {
     ASSERT(isMainThread());
-    CrossOriginPreflightResultHashMap::iterator cacheIt = m_preflightHashMap.find(std::make_pair(origin, url));
+    CrossOriginPreflightResultHashMap::iterator cacheIt = m_preflightHashMap.find(make_pair(origin, url));
     if (cacheIt == m_preflightHashMap.end())
         return false;
 
     if (cacheIt->second->allowsRequest(includeCredentials, method, requestHeaders))
         return true;
 
-    delete cacheIt->second;
     m_preflightHashMap.remove(cacheIt);
     return false;
 }
@@ -185,7 +179,6 @@ bool CrossOriginPreflightResultCache::canSkipPreflight(const String& origin, con
 void CrossOriginPreflightResultCache::empty()
 {
     ASSERT(isMainThread());
-    deleteAllValues(m_preflightHashMap);
     m_preflightHashMap.clear();
 }
 
index 115d833..2850492 100644 (file)
@@ -78,7 +78,7 @@ namespace WebCore {
     private:
         CrossOriginPreflightResultCache() { }
 
-        typedef HashMap<std::pair<String, KURL>, CrossOriginPreflightResultCacheItem*> CrossOriginPreflightResultHashMap;
+        typedef HashMap<std::pair<String, KURL>, OwnPtr<CrossOriginPreflightResultCacheItem> > CrossOriginPreflightResultHashMap;
 
         CrossOriginPreflightResultHashMap m_preflightHashMap;
     };