Changeset 149453 in webkit


Ignore:
Timestamp:
May 1, 2013 2:02:13 PM (11 years ago)
Author:
benjamin@webkit.org
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]):

Location:
trunk/Source/WebKit/mac
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/mac/ChangeLog

    r149423 r149453  
     12013-05-01  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Simplify WebHTMLRepresentation supportedMIMETypes methods
     4        https://bugs.webkit.org/show_bug.cgi?id=115314
     5
     6        Reviewed by Darin Adler.
     7
     8        The initialization was surprisingly complex because of DEFINE_STATIC_LOCAL.
     9        First, a new pointer was allocated on the heap with fast malloc (for RetainPtr<NSArray>).
     10        Then a new NSMutableArray was allocated but immediately put on the autorelease pool.
     11        Finally, that array was retained by the RetainPtr.
     12
     13        This patch changes the code to only leak the NSMutableArray memory. There
     14        is no fastMalloc, nor any use of the autorelease pool.
     15
     16        * WebView/WebHTMLRepresentation.mm:
     17        (createArrayWithStrings):
     18        (createArrayByConcatenatingArrays):
     19        (+[WebHTMLRepresentation supportedMIMETypes]):
     20        (+[WebHTMLRepresentation supportedNonImageMIMETypes]):
     21        (+[WebHTMLRepresentation supportedImageMIMETypes]):
     22        (+[WebHTMLRepresentation unsupportedTextMIMETypes]):
     23
    1242013-04-30  Darin Adler  <darin@apple.com>
    225
  • trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm

    r148545 r149453  
    8585@implementation WebHTMLRepresentation
    8686
    87 static NSArray *stringArray(const HashSet<String>& set)
    88 {
    89     NSMutableArray *array = [NSMutableArray arrayWithCapacity:set.size()];
     87static NSMutableArray *createArrayWithStrings(const HashSet<String>& set) NS_RETURNS_RETAINED;
     88static NSMutableArray *createArrayWithStrings(const HashSet<String>& set)
     89{
     90    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:set.size()];
    9091    HashSet<String>::const_iterator end = set.end();
    9192    for (HashSet<String>::const_iterator it = set.begin(); it != end; ++it)
     
    9495}
    9596
    96 static NSArray *concatenateArrays(NSArray *first, NSArray *second)
    97 {
    98     NSMutableArray *result = [[first mutableCopy] autorelease];
     97static NSMutableArray *createArrayByConcatenatingArrays(NSArray *first, NSArray *second) NS_RETURNS_RETAINED;
     98static NSMutableArray *createArrayByConcatenatingArrays(NSArray *first, NSArray *second)
     99{
     100    NSMutableArray *result = [first mutableCopy];
    99101    [result addObjectsFromArray:second];
    100102    return result;
     
    103105+ (NSArray *)supportedMIMETypes
    104106{
    105     DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedMIMETypes, (concatenateArrays([self supportedNonImageMIMETypes], [self supportedImageMIMETypes])));
    106     return staticSupportedMIMETypes.get();
     107    static __unsafe_unretained NSArray *staticSupportedMIMETypes = createArrayByConcatenatingArrays([self supportedNonImageMIMETypes], [self supportedImageMIMETypes]);
     108    return staticSupportedMIMETypes;
    107109}
    108110
    109111+ (NSArray *)supportedNonImageMIMETypes
    110112{
    111     DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedNonImageMIMETypes, (stringArray(MIMETypeRegistry::getSupportedNonImageMIMETypes())));
    112     return staticSupportedNonImageMIMETypes.get();
     113    static __unsafe_unretained NSArray *staticSupportedNonImageMIMETypes = createArrayWithStrings(MIMETypeRegistry::getSupportedNonImageMIMETypes());
     114    return staticSupportedNonImageMIMETypes;
    113115}
    114116
    115117+ (NSArray *)supportedImageMIMETypes
    116118{
    117     DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticSupportedImageMIMETypes, (stringArray(MIMETypeRegistry::getSupportedImageMIMETypes())));
    118     return staticSupportedImageMIMETypes.get();
     119    static __unsafe_unretained NSArray *staticSupportedImageMIMETypes = createArrayWithStrings(MIMETypeRegistry::getSupportedImageMIMETypes());
     120    return staticSupportedImageMIMETypes;
    119121}
    120122
    121123+ (NSArray *)unsupportedTextMIMETypes
    122124{
    123     DEFINE_STATIC_LOCAL(RetainPtr<NSArray>, staticUnsupportedTextMIMETypes, (stringArray(MIMETypeRegistry::getUnsupportedTextMIMETypes())));
    124     return staticUnsupportedTextMIMETypes.get();
     125    static __unsafe_unretained NSArray *staticUnsupportedTextMIMETypes = createArrayWithStrings(MIMETypeRegistry::getUnsupportedTextMIMETypes());
     126    return staticUnsupportedTextMIMETypes;
    125127}
    126128
Note: See TracChangeset for help on using the changeset viewer.