Title: [174862] trunk/Source/WebCore
Revision
174862
Author
[email protected]
Date
2014-10-18 10:05:24 -0700 (Sat, 18 Oct 2014)

Log Message

[Mac] Use Fast enumeration consistently in WebFontCache.mm
https://bugs.webkit.org/show_bug.cgi?id=137791

Reviewed by Darin Adler.

Use fast enumeration consistently in WebFontCache.mm as this results in
more efficient, concise and safer code.

No new tests, no behavior change.

* platform/mac/WebFontCache.mm:
(+[WebFontCache getTraits:inFamily:]):
Reserve Vector capacity before the loop as we know how many traits we
are going to append. Also use uncheckedAppend() for performance.

(+[WebFontCache internalFontWithFamily:traits:weight:size:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174861 => 174862)


--- trunk/Source/WebCore/ChangeLog	2014-10-18 15:54:59 UTC (rev 174861)
+++ trunk/Source/WebCore/ChangeLog	2014-10-18 17:05:24 UTC (rev 174862)
@@ -1,3 +1,22 @@
+2014-10-18  Chris Dumez  <[email protected]>
+
+        [Mac] Use Fast enumeration consistently in WebFontCache.mm
+        https://bugs.webkit.org/show_bug.cgi?id=137791
+
+        Reviewed by Darin Adler.
+
+        Use fast enumeration consistently in WebFontCache.mm as this results in
+        more efficient, concise and safer code.
+
+        No new tests, no behavior change.
+
+        * platform/mac/WebFontCache.mm:
+        (+[WebFontCache getTraits:inFamily:]):
+        Reserve Vector capacity before the loop as we know how many traits we
+        are going to append. Also use uncheckedAppend() for performance.
+
+        (+[WebFontCache internalFontWithFamily:traits:weight:size:]):
+
 2014-10-18  Chris Fleizach  <[email protected]>
 
         AX: Tables with <colgroups> are not reporting table column headers

Modified: trunk/Source/WebCore/platform/mac/WebFontCache.mm (174861 => 174862)


--- trunk/Source/WebCore/platform/mac/WebFontCache.mm	2014-10-18 15:54:59 UTC (rev 174861)
+++ trunk/Source/WebCore/platform/mac/WebFontCache.mm	2014-10-18 17:05:24 UTC (rev 174862)
@@ -146,18 +146,15 @@
 {
     NSFontManager *fontManager = [NSFontManager sharedFontManager];
 
-    NSEnumerator *e = [[fontManager availableFontFamilies] objectEnumerator];
     NSString *availableFamily;
-    while ((availableFamily = [e nextObject])) {
+    for (availableFamily in [fontManager availableFontFamilies]) {
         if ([desiredFamily caseInsensitiveCompare:availableFamily] == NSOrderedSame)
             break;
     }
 
     if (!availableFamily) {
         // Match by PostScript name.
-        NSEnumerator *availableFonts = [[fontManager availableFonts] objectEnumerator];
-        NSString *availableFont;
-        while ((availableFont = [availableFonts nextObject])) {
+        for (NSString *availableFont in [fontManager availableFonts]) {
             if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrderedSame) {
                 NSFont *font = [NSFont fontWithName:availableFont size:10];
                 NSInteger weight = [fontManager weightOfFont:font];
@@ -168,15 +165,13 @@
         return;
     }
 
-    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];    
-    unsigned n = [fonts count];
-    unsigned i;
-    for (i = 0; i < n; i++) {
-        NSArray *fontInfo = [fonts objectAtIndex:i];
+    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
+    traitsMasks.reserveCapacity([fonts count]);
+    for (NSArray *fontInfo in fonts) {
         // Array indices must be hard coded because of lame AppKit API.
         NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
         NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValue];
-        traitsMasks.append(toTraitsMask(fontTraits, fontWeight));
+        traitsMasks.uncheckedAppend(toTraitsMask(fontTraits, fontWeight));
     }
 }
 
@@ -242,12 +237,8 @@
     NSFontTraitMask chosenTraits = 0;
     NSString *chosenFullName = 0;
 
-    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];    
-    unsigned n = [fonts count];
-    unsigned i;
-    for (i = 0; i < n; i++) {
-        NSArray *fontInfo = [fonts objectAtIndex:i];
-
+    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
+    for (NSArray *fontInfo in fonts) {
         // Array indices must be hard coded because of lame AppKit API.
         NSString *fontFullName = [fontInfo objectAtIndex:0];
         NSInteger fontWeight = [[fontInfo objectAtIndex:2] intValue];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to