Title: [149453] trunk/Source/WebKit/mac
Revision
149453
Author
[email protected]
Date
2013-05-01 14:02:13 -0700 (Wed, 01 May 2013)

Log Message

Simplify WebHTMLRepresentation supportedMIMETypes methods
https://bugs.webkit.org/show_bug.cgi?id=115314

Reviewed by Darin Adler.

The initialization was surprisingly complex because of DEFINE_STATIC_LOCAL.
First, a new pointer was allocated on the heap with fast malloc (for RetainPtr<NSArray>).
Then a new NSMutableArray was allocated but immediately put on the autorelease pool.
Finally, that array was retained by the RetainPtr.

This patch changes the code to only leak the NSMutableArray memory. There
is no fastMalloc, nor any use of the autorelease pool.

* WebView/WebHTMLRepresentation.mm:
(createArrayWithStrings):
(createArrayByConcatenatingArrays):
(+[WebHTMLRepresentation supportedMIMETypes]):
(+[WebHTMLRepresentation supportedNonImageMIMETypes]):
(+[WebHTMLRepresentation supportedImageMIMETypes]):
(+[WebHTMLRepresentation unsupportedTextMIMETypes]):

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (149452 => 149453)


--- trunk/Source/WebKit/mac/ChangeLog	2013-05-01 20:58:32 UTC (rev 149452)
+++ trunk/Source/WebKit/mac/ChangeLog	2013-05-01 21:02:13 UTC (rev 149453)
@@ -1,3 +1,26 @@
+2013-05-01  Benjamin Poulain  <[email protected]>
+
+        Simplify WebHTMLRepresentation supportedMIMETypes methods
+        https://bugs.webkit.org/show_bug.cgi?id=115314
+
+        Reviewed by Darin Adler.
+
+        The initialization was surprisingly complex because of DEFINE_STATIC_LOCAL.
+        First, a new pointer was allocated on the heap with fast malloc (for RetainPtr<NSArray>).
+        Then a new NSMutableArray was allocated but immediately put on the autorelease pool.
+        Finally, that array was retained by the RetainPtr.
+
+        This patch changes the code to only leak the NSMutableArray memory. There
+        is no fastMalloc, nor any use of the autorelease pool.
+
+        * WebView/WebHTMLRepresentation.mm:
+        (createArrayWithStrings):
+        (createArrayByConcatenatingArrays):
+        (+[WebHTMLRepresentation supportedMIMETypes]):
+        (+[WebHTMLRepresentation supportedNonImageMIMETypes]):
+        (+[WebHTMLRepresentation supportedImageMIMETypes]):
+        (+[WebHTMLRepresentation unsupportedTextMIMETypes]):
+
 2013-04-30  Darin Adler  <[email protected]>
 
         [Mac] Remove adoptNS/retain pairs, since the two cancel each other out

Modified: trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm (149452 => 149453)


--- trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm	2013-05-01 20:58:32 UTC (rev 149452)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm	2013-05-01 21:02:13 UTC (rev 149453)
@@ -84,44 +84,46 @@
 
 @implementation WebHTMLRepresentation
 
-static NSArray *stringArray(const HashSet<String>& set)
+static NSMutableArray *createArrayWithStrings(const HashSet<String>& set) NS_RETURNS_RETAINED;
+static NSMutableArray *createArrayWithStrings(const HashSet<String>& set)
 {
-    NSMutableArray *array = [NSMutableArray arrayWithCapacity:set.size()];
+    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:set.size()];
     HashSet<String>::const_iterator end = set.end();
     for (HashSet<String>::const_iterator it = set.begin(); it != end; ++it)
         [array addObject:(NSString *)(*it)];
     return array;
 }
 
-static NSArray *concatenateArrays(NSArray *first, NSArray *second)
+static NSMutableArray *createArrayByConcatenatingArrays(NSArray *first, NSArray *second) NS_RETURNS_RETAINED;
+static NSMutableArray *createArrayByConcatenatingArrays(NSArray *first, NSArray *second)
 {
-    NSMutableArray *result = [[first mutableCopy] autorelease];
+    NSMutableArray *result = [first mutableCopy];
     [result addObjectsFromArray:second];
     return result;
 }
 
 + (NSArray *)supportedMIMETypes
 {
-    DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedMIMETypes, (concatenateArrays([self supportedNonImageMIMETypes], [self supportedImageMIMETypes])));
-    return staticSupportedMIMETypes.get();
+    static __unsafe_unretained NSArray *staticSupportedMIMETypes = createArrayByConcatenatingArrays([self supportedNonImageMIMETypes], [self supportedImageMIMETypes]);
+    return staticSupportedMIMETypes;
 }
 
 + (NSArray *)supportedNonImageMIMETypes
 {
-    DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedNonImageMIMETypes, (stringArray(MIMETypeRegistry::getSupportedNonImageMIMETypes())));
-    return staticSupportedNonImageMIMETypes.get();
+    static __unsafe_unretained NSArray *staticSupportedNonImageMIMETypes = createArrayWithStrings(MIMETypeRegistry::getSupportedNonImageMIMETypes());
+    return staticSupportedNonImageMIMETypes;
 }
 
 + (NSArray *)supportedImageMIMETypes
 {
-    DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedImageMIMETypes, (stringArray(MIMETypeRegistry::getSupportedImageMIMETypes())));
-    return staticSupportedImageMIMETypes.get();
+    static __unsafe_unretained NSArray *staticSupportedImageMIMETypes = createArrayWithStrings(MIMETypeRegistry::getSupportedImageMIMETypes());
+    return staticSupportedImageMIMETypes;
 }
 
 + (NSArray *)unsupportedTextMIMETypes
 {
-    DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticUnsupportedTextMIMETypes, (stringArray(MIMETypeRegistry::getUnsupportedTextMIMETypes())));
-    return staticUnsupportedTextMIMETypes.get();
+    static __unsafe_unretained NSArray *staticUnsupportedTextMIMETypes = createArrayWithStrings(MIMETypeRegistry::getUnsupportedTextMIMETypes());
+    return staticUnsupportedTextMIMETypes;
 }
 
 - (id)init
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to