Avoid fetching visitedDependentColor() so many times in editing code
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jul 2018 02:15:49 +0000 (02:15 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Jul 2018 02:15:49 +0000 (02:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187676

Reviewed by Zalan Bujtas.

editingAttributedStringFromRange called style.visitedDependentColor() twice for each property,
and fontAttributesForSelectionStart() called it two or three times. Use a local Color variable
to avoid so many calls. Also replace a call to alpha() with isVisible() which makes the usage more clear.

No behavior change.

* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::fontAttributesForSelectionStart const):
* editing/cocoa/HTMLConverter.mm:
(WebCore::editingAttributedStringFromRange):

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

Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/EditorCocoa.mm
Source/WebCore/editing/cocoa/HTMLConverter.mm

index 8991d4e..ee5a457 100644 (file)
@@ -1,3 +1,21 @@
+2018-07-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Avoid fetching visitedDependentColor() so many times in editing code
+        https://bugs.webkit.org/show_bug.cgi?id=187676
+
+        Reviewed by Zalan Bujtas.
+        
+        editingAttributedStringFromRange called style.visitedDependentColor() twice for each property,
+        and fontAttributesForSelectionStart() called it two or three times. Use a local Color variable
+        to avoid so many calls. Also replace a call to alpha() with isVisible() which makes the usage more clear.
+
+        No behavior change.
+
+        * editing/cocoa/EditorCocoa.mm:
+        (WebCore::Editor::fontAttributesForSelectionStart const):
+        * editing/cocoa/HTMLConverter.mm:
+        (WebCore::editingAttributedStringFromRange):
+
 2018-07-13  Youenn Fablet  <youenn@apple.com>
 
         Support connecting a MediaStreamAudioDestinationNode to RTCPeerConnection
index 063d723..432dc19 100644 (file)
@@ -93,11 +93,13 @@ RetainPtr<NSDictionary> Editor::fontAttributesForSelectionStart() const
 
     // FIXME: Why would we not want to retrieve these attributes on iOS?
 #if PLATFORM(MAC)
-    if (style->visitedDependentColor(CSSPropertyBackgroundColor).isVisible())
-        [attributes setObject:nsColor(style->visitedDependentColor(CSSPropertyBackgroundColor)) forKey:NSBackgroundColorAttributeName];
+    Color backgroundColor = style->visitedDependentColor(CSSPropertyBackgroundColor);
+    if (backgroundColor.isVisible())
+        [attributes setObject:nsColor(backgroundColor) forKey:NSBackgroundColorAttributeName];
 
-    if (style->visitedDependentColor(CSSPropertyColor).isValid() && !Color::isBlackColor(style->visitedDependentColor(CSSPropertyColor)))
-        [attributes setObject:nsColor(style->visitedDependentColor(CSSPropertyColor)) forKey:NSForegroundColorAttributeName];
+    Color foregroundColor = style->visitedDependentColor(CSSPropertyColor);
+    if (foregroundColor.isValid() && !Color::isBlackColor(foregroundColor))
+        [attributes setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
 
     const ShadowData* shadowData = style->textShadow();
     if (shadowData) {
index 2144652..3907235 100644 (file)
@@ -2513,12 +2513,16 @@ NSAttributedString *editingAttributedStringFromRange(Range& range, IncludeImages
             [attrs.get() setObject:toNSFont(font) forKey:NSFontAttributeName];
         else
             [attrs.get() setObject:[fontManager convertFont:WebDefaultFont() toSize:style.fontCascade().primaryFont().platformData().size()] forKey:NSFontAttributeName];
-        if (style.visitedDependentColor(CSSPropertyColor).alpha())
-            [attrs.get() setObject:nsColor(style.visitedDependentColor(CSSPropertyColor)) forKey:NSForegroundColorAttributeName];
+
+        Color foregroundColor = style.visitedDependentColor(CSSPropertyColor);
+        if (foregroundColor.isVisible())
+            [attrs.get() setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
         else
             [attrs.get() removeObjectForKey:NSForegroundColorAttributeName];
-        if (style.visitedDependentColor(CSSPropertyBackgroundColor).alpha())
-            [attrs.get() setObject:nsColor(style.visitedDependentColor(CSSPropertyBackgroundColor)) forKey:NSBackgroundColorAttributeName];
+
+        Color backgroundColor = style.visitedDependentColor(CSSPropertyBackgroundColor);
+        if (backgroundColor.isVisible())
+            [attrs.get() setObject:nsColor(backgroundColor) forKey:NSBackgroundColorAttributeName];
         else
             [attrs.get() removeObjectForKey:NSBackgroundColorAttributeName];