<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[165635] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/165635">165635</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2014-03-14 12:31:25 -0700 (Fri, 14 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
https://bugs.webkit.org/show_bug.cgi?id=130226

Reviewed by Andreas Kling.

Extracted HTMLConverterCaches in C++ that directly calls getPropertyCSSValue on computed style
and inline style to avoid creating Objective-C wrappers for CSSComputedStyleDeclaration.

This improves the runtime of PerformanceTests/Interactive/CopyAll.html from 31-32s to 25-26s (20%).

* platform/mac/HTMLConverter.h:
* platform/mac/HTMLConverter.mm:
(HTMLConverterCaches::computedStylePropertyForElement):
(HTMLConverterCaches::inlineStylePropertyForElement):
(stringFromCSSValue):
(-[WebHTMLConverter _computedStringForNode:property:]):
(floatValueFromPrimitiveValue):
(_getFloat):
(-[WebHTMLConverter _getComputedFloat:forNode:property:]):
(-[WebHTMLConverter _computedColorForNode:property:]):
(-[WebHTMLConverter dealloc]):
(-[WebHTMLConverter init]):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformmacHTMLConverterh">trunk/Source/WebCore/platform/mac/HTMLConverter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacHTMLConvertermm">trunk/Source/WebCore/platform/mac/HTMLConverter.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/ChangeLog        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-03-13  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        [Mac] Avoid creating DOMCSSStyleDeclaration in WebHTMLConverter
+        https://bugs.webkit.org/show_bug.cgi?id=130226
+
+        Reviewed by Andreas Kling.
+
+        Extracted HTMLConverterCaches in C++ that directly calls getPropertyCSSValue on computed style
+        and inline style to avoid creating Objective-C wrappers for CSSComputedStyleDeclaration.
+
+        This improves the runtime of PerformanceTests/Interactive/CopyAll.html from 31-32s to 25-26s (20%).
+
+        * platform/mac/HTMLConverter.h:
+        * platform/mac/HTMLConverter.mm:
+        (HTMLConverterCaches::computedStylePropertyForElement):
+        (HTMLConverterCaches::inlineStylePropertyForElement):
+        (stringFromCSSValue):
+        (-[WebHTMLConverter _computedStringForNode:property:]):
+        (floatValueFromPrimitiveValue):
+        (_getFloat):
+        (-[WebHTMLConverter _getComputedFloat:forNode:property:]):
+        (-[WebHTMLConverter _computedColorForNode:property:]):
+        (-[WebHTMLConverter dealloc]):
+        (-[WebHTMLConverter init]):
+
</ins><span class="cx"> 2014-03-14  James Craig  &lt;jcraig@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: AXI: Include Role as an extra attribute in the page overlay.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacHTMLConverterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.h (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/HTMLConverter.h        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.h        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -31,6 +31,8 @@
</span><span class="cx">     class Range;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+class HTMLConverterCaches;
+
</ins><span class="cx"> @interface WebHTMLConverter : NSObject {
</span><span class="cx">     NSMutableAttributedString *_attrStr;
</span><span class="cx">     NSMutableDictionary *_documentAttrs;
</span><span class="lines">@@ -54,7 +56,6 @@
</span><span class="cx">     NSMutableArray *_textTableRows;
</span><span class="cx">     NSMutableArray *_textTableRowArrays;
</span><span class="cx">     NSMutableArray *_textTableRowBackgroundColors;
</span><del>-    NSMutableDictionary *_computedStylesForElements;
</del><span class="cx">     NSMutableDictionary *_specifiedStylesForElements;
</span><span class="cx">     NSMutableDictionary *_stringsForNodes;
</span><span class="cx">     NSMutableDictionary *_floatsForNodes;
</span><span class="lines">@@ -69,6 +70,8 @@
</span><span class="cx">     NSInteger _errorCode;
</span><span class="cx">     NSInteger _quoteLevel;
</span><span class="cx"> 
</span><ins>+    std::unique_ptr&lt;HTMLConverterCaches&gt; _caches;
+
</ins><span class="cx">     struct {
</span><span class="cx">         unsigned int isSoft:1;
</span><span class="cx">         unsigned int reachedStart:1;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacHTMLConvertermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/HTMLConverter.mm (165634 => 165635)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/HTMLConverter.mm        2014-03-14 19:13:20 UTC (rev 165634)
+++ trunk/Source/WebCore/platform/mac/HTMLConverter.mm        2014-03-14 19:31:25 UTC (rev 165635)
</span><span class="lines">@@ -29,12 +29,18 @@
</span><span class="cx"> #import &quot;ArchiveResource.h&quot;
</span><span class="cx"> #import &quot;CachedImage.h&quot;
</span><span class="cx"> #import &quot;ColorMac.h&quot;
</span><ins>+#import &quot;CSSComputedStyleDeclaration.h&quot;
+#import &quot;CSSParser.h&quot;
+#import &quot;CSSPrimitiveValue.h&quot;
</ins><span class="cx"> #import &quot;Document.h&quot;
</span><span class="cx"> #import &quot;DocumentLoader.h&quot;
</span><ins>+#import &quot;DOMCSSPrimitiveValueInternal.h&quot;
</ins><span class="cx"> #import &quot;DOMDocumentInternal.h&quot;
</span><span class="cx"> #import &quot;DOMElementInternal.h&quot;
</span><span class="cx"> #import &quot;DOMHTMLTableCellElement.h&quot;
</span><ins>+#import &quot;DOMNodeInternal.h&quot;
</ins><span class="cx"> #import &quot;DOMPrivate.h&quot;
</span><ins>+#import &quot;DOMRGBColorInternal.h&quot;
</ins><span class="cx"> #import &quot;DOMRangeInternal.h&quot;
</span><span class="cx"> #import &quot;Element.h&quot;
</span><span class="cx"> #import &quot;Font.h&quot;
</span><span class="lines">@@ -43,8 +49,11 @@
</span><span class="cx"> #import &quot;HTMLNames.h&quot;
</span><span class="cx"> #import &quot;HTMLParserIdioms.h&quot;
</span><span class="cx"> #import &quot;LoaderNSURLExtras.h&quot;
</span><ins>+#import &quot;RGBColor.h&quot;
</ins><span class="cx"> #import &quot;RenderImage.h&quot;
</span><span class="cx"> #import &quot;SoftLinking.h&quot;
</span><ins>+#import &quot;StyleProperties.h&quot;
+#import &quot;StyledElement.h&quot;
</ins><span class="cx"> #import &quot;TextIterator.h&quot;
</span><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><span class="cx"> #import &lt;wtf/ASCIICType.h&gt;
</span><span class="lines">@@ -389,6 +398,15 @@
</span><span class="cx"> // Additional control Unicode characters
</span><span class="cx"> const unichar WebNextLineCharacter = 0x0085;
</span><span class="cx"> 
</span><ins>+class HTMLConverterCaches {
+public:
+    PassRefPtr&lt;CSSValue&gt; computedStylePropertyForElement(Element&amp;, String&amp;);
+    PassRefPtr&lt;CSSValue&gt; inlineStylePropertyForElement(Element&amp;, String&amp;);
+
+private:
+    HashMap&lt;Element*, std::unique_ptr&lt;ComputedStyleExtractor&gt;&gt; m_computedStyles;
+};
+
</ins><span class="cx"> @interface NSTextList (WebCoreNSTextListDetails)
</span><span class="cx"> + (NSDictionary *)_standardMarkerAttributesForAttributes:(NSDictionary *)attrs;
</span><span class="cx"> @end
</span><span class="lines">@@ -543,82 +561,76 @@
</span><span class="cx">     return array;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (DOMCSSStyleDeclaration *)_computedStyleForElement:(DOMElement *)element
</del><ins>+PassRefPtr&lt;CSSValue&gt; HTMLConverterCaches::computedStylePropertyForElement(Element&amp; element, String&amp; propertyName)
</ins><span class="cx"> {
</span><del>-    DOMDocument *document = [element ownerDocument];
-    DOMCSSStyleDeclaration *result = nil;
-    result = [_computedStylesForElements objectForKey:element];
-    if (result) {
-        if ([result isEqual:[NSNull null]])
-            result = nil;
-    } else {
-        result = [document getComputedStyle:element pseudoElement:@&quot;&quot;] ;
-        [_computedStylesForElements setObject:(result ? (id)result : (id)[NSNull null]) forKey:element];
-    }
-    return result;
</del><ins>+    CSSPropertyID propetyId = cssPropertyID(propertyName);
+    if (propetyId == CSSPropertyInvalid)
+        return nullptr;
+
+    auto result = m_computedStyles.add(&amp;element, nullptr);
+    if (result.isNewEntry)
+        result.iterator-&gt;value = std::make_unique&lt;ComputedStyleExtractor&gt;(&amp;element, true);
+    ComputedStyleExtractor&amp; computedStyle = *result.iterator-&gt;value;
+    return computedStyle.propertyValue(propetyId);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (DOMCSSStyleDeclaration *)_specifiedStyleForElement:(DOMElement *)element
</del><ins>+PassRefPtr&lt;CSSValue&gt; HTMLConverterCaches::inlineStylePropertyForElement(Element&amp; element, String&amp; propertyName)
</ins><span class="cx"> {
</span><del>-    DOMCSSStyleDeclaration *result = [_specifiedStylesForElements objectForKey:element];
-    if (result) {
-        if ([result isEqual:[NSNull null]])
-            result = nil;
-    } else {
-        result = [element style];
-        [_specifiedStylesForElements setObject:(result ? (id)result : (id)[NSNull null]) forKey:element];
</del><ins>+    CSSPropertyID propetyId = cssPropertyID(propertyName);
+    if (propetyId == CSSPropertyInvalid || !element.isStyledElement())
+        return nullptr;
+    const StyleProperties* properties = toStyledElement(element).inlineStyle();
+    if (!properties)
+        return nullptr;
+    return properties-&gt;getPropertyCSSValue(propetyId);
+}
+
+static bool stringFromCSSValue(CSSValue&amp; value, String&amp; result)
+{
+    if (value.isPrimitiveValue()) {
+        unsigned short primitiveType = toCSSPrimitiveValue(value).primitiveType();
+        if (primitiveType == CSSPrimitiveValue::CSS_STRING || primitiveType == CSSPrimitiveValue::CSS_URI ||
+            primitiveType == CSSPrimitiveValue::CSS_IDENT || primitiveType == CSSPrimitiveValue::CSS_ATTR) {
+            String stringValue = value.cssText();
+            if (stringValue.length()) {
+                result = stringValue;
+                return true;
+            }
+        }
+    } else if (value.isValueList()) {
+        result = value.cssText();
+        return true;
</ins><span class="cx">     }
</span><del>-    return result;
</del><ins>+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (NSString *)_computedStringForNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><del>-    NSString *result = nil;
-    BOOL inherit = YES;
-    DOMElement *element = (DOMElement *)node;    
-    if (element &amp;&amp; [element nodeType] == DOM_ELEMENT_NODE) {
-        DOMCSSStyleDeclaration *computedStyle;
-        DOMCSSStyleDeclaration *specifiedStyle;
-        inherit = NO;
-        if (!result &amp;&amp; (computedStyle = [self _computedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
-            if (computedValue) {
-                unsigned short valueType = [computedValue cssValueType];
-                if (valueType == DOM_CSS_PRIMITIVE_VALUE) {
-                    unsigned short primitiveType = [computedValue primitiveType];
-                    if (primitiveType == DOM_CSS_STRING || primitiveType == DOM_CSS_URI || primitiveType == DOM_CSS_IDENT || primitiveType == DOM_CSS_ATTR) {
-                        result = [computedValue getStringValue];
-                        if (result &amp;&amp; ![result length])
-                            result = nil;
-                    }
-                } else if (valueType == DOM_CSS_VALUE_LIST)
-                    result = [computedStyle getPropertyValue:key];
-            }
</del><ins>+    bool haveResult = false;
+    String result;
+    bool inherit = true;
+    Node* coreNode = core(node);
+    if (coreNode &amp;&amp; coreNode-&gt;isElementNode()) {
+        Element&amp; element = toElement(*coreNode);
+        String propertyName = key;
+        inherit = false;
+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;computedStylePropertyForElement(element, propertyName))
+                haveResult = stringFromCSSValue(*value, result);
</ins><span class="cx">         }
</span><del>-        if (!result &amp;&amp; (specifiedStyle = [self _specifiedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
-            if (specifiedValue) {
-                unsigned short valueType = [specifiedValue cssValueType];
-                if (valueType == DOM_CSS_PRIMITIVE_VALUE) {
-                    unsigned short primitiveType = [specifiedValue primitiveType];
-                    if (primitiveType == DOM_CSS_STRING || primitiveType == DOM_CSS_URI || primitiveType == DOM_CSS_IDENT || primitiveType == DOM_CSS_ATTR) {
-                        result = [specifiedValue getStringValue];
-                        if (result &amp;&amp; ![result length])
-                            result = nil;
-                        if (!result)
-                            result = [specifiedStyle getPropertyValue:key];
-                    }
-                } else if (valueType == DOM_CSS_INHERIT)
-                    inherit = YES;
-                else if (valueType == DOM_CSS_VALUE_LIST)
-                    result = [specifiedStyle getPropertyValue:key];
</del><ins>+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;computedStylePropertyForElement(element, propertyName)) {
+                if (value-&gt;isInheritedValue())
+                    inherit = true;
+                else
+                    haveResult = stringFromCSSValue(*value, result);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><del>-        if (!result) {
-            Element* coreElement = core(element);
</del><ins>+        Element* coreElement = &amp;element;
+        if (!haveResult) {
</ins><span class="cx">             if ([@&quot;display&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(headTag) || coreElement-&gt;hasTagName(scriptTag) || coreElement-&gt;hasTagName(appletTag) || coreElement-&gt;hasTagName(noframesTag))
</span><del>-                    result = @&quot;none&quot;;
</del><ins>+                    result = &quot;none&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(addressTag) || coreElement-&gt;hasTagName(blockquoteTag) || coreElement-&gt;hasTagName(bodyTag) || coreElement-&gt;hasTagName(centerTag)
</span><span class="cx">                          || coreElement-&gt;hasTagName(ddTag) || coreElement-&gt;hasTagName(dirTag) || coreElement-&gt;hasTagName(divTag) || coreElement-&gt;hasTagName(dlTag)
</span><span class="cx">                          || coreElement-&gt;hasTagName(dtTag) || coreElement-&gt;hasTagName(fieldsetTag) || coreElement-&gt;hasTagName(formTag) || coreElement-&gt;hasTagName(frameTag)
</span><span class="lines">@@ -626,61 +638,61 @@
</span><span class="cx">                          || coreElement-&gt;hasTagName(h2Tag) || coreElement-&gt;hasTagName(h3Tag) || coreElement-&gt;hasTagName(h4Tag) || coreElement-&gt;hasTagName(h5Tag)
</span><span class="cx">                          || coreElement-&gt;hasTagName(h6Tag) || coreElement-&gt;hasTagName(iframeTag) || coreElement-&gt;hasTagName(menuTag) || coreElement-&gt;hasTagName(noscriptTag)
</span><span class="cx">                          || coreElement-&gt;hasTagName(olTag) || coreElement-&gt;hasTagName(pTag) || coreElement-&gt;hasTagName(preTag) || coreElement-&gt;hasTagName(ulTag))
</span><del>-                    result = @&quot;block&quot;;
</del><ins>+                    result = &quot;block&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(liTag))
</span><del>-                    result = @&quot;list-item&quot;;
</del><ins>+                    result = &quot;list-item&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(tableTag))
</span><del>-                    result = @&quot;table&quot;;
</del><ins>+                    result = &quot;table&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(trTag))
</span><del>-                    result = @&quot;table-row&quot;;
</del><ins>+                    result = &quot;table-row&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(thTag) || coreElement-&gt;hasTagName(tdTag))
</span><del>-                    result = @&quot;table-cell&quot;;
</del><ins>+                    result = &quot;table-cell&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(theadTag))
</span><del>-                    result = @&quot;table-header-group&quot;;
</del><ins>+                    result = &quot;table-header-group&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(tbodyTag))
</span><del>-                    result = @&quot;table-row-group&quot;;
</del><ins>+                    result = &quot;table-row-group&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(tfootTag))
</span><del>-                    result = @&quot;table-footer-group&quot;;
</del><ins>+                    result = &quot;table-footer-group&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(colTag))
</span><del>-                    result = @&quot;table-column&quot;;
</del><ins>+                    result = &quot;table-column&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(colgroupTag))
</span><del>-                    result = @&quot;table-column-group&quot;;
</del><ins>+                    result = &quot;table-column-group&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(captionTag))
</span><del>-                    result = @&quot;table-caption&quot;;
</del><ins>+                    result = &quot;table-caption&quot;;
</ins><span class="cx">             } else if ([@&quot;white-space&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(preTag))
</span><del>-                    result = @&quot;pre&quot;;
</del><ins>+                    result = &quot;pre&quot;;
</ins><span class="cx">                 else
</span><span class="cx">                     inherit = YES;
</span><span class="cx">             } else if ([@&quot;font-style&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(iTag) || coreElement-&gt;hasTagName(citeTag) || coreElement-&gt;hasTagName(emTag) || coreElement-&gt;hasTagName(varTag) || coreElement-&gt;hasTagName(addressTag))
</span><del>-                    result = @&quot;italic&quot;;
</del><ins>+                    result = &quot;italic&quot;;
</ins><span class="cx">                 else
</span><span class="cx">                     inherit = YES;
</span><span class="cx">             } else if ([@&quot;font-weight&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(bTag) || coreElement-&gt;hasTagName(strongTag) || coreElement-&gt;hasTagName(thTag))
</span><del>-                    result = @&quot;bolder&quot;;
</del><ins>+                    result = &quot;bolder&quot;;
</ins><span class="cx">                 else
</span><span class="cx">                     inherit = YES;
</span><span class="cx">             } else if ([@&quot;text-decoration&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(uTag) || coreElement-&gt;hasTagName(insTag))
</span><del>-                    result = @&quot;underline&quot;;
</del><ins>+                    result = &quot;underline&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(sTag) || coreElement-&gt;hasTagName(strikeTag) || coreElement-&gt;hasTagName(delTag))
</span><del>-                    result = @&quot;line-through&quot;;
</del><ins>+                    result = &quot;line-through&quot;;
</ins><span class="cx">                 else
</span><span class="cx">                     inherit = YES; // ??? this is not strictly correct
</span><span class="cx">             } else if ([@&quot;text-align&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(centerTag) || coreElement-&gt;hasTagName(captionTag) || coreElement-&gt;hasTagName(thTag))
</span><del>-                    result = @&quot;center&quot;;
</del><ins>+                    result = &quot;center&quot;;
</ins><span class="cx">                 else
</span><span class="cx">                     inherit = YES;
</span><span class="cx">             } else if ([@&quot;vertical-align&quot; isEqualToString:key]) {
</span><span class="cx">                 if (coreElement-&gt;hasTagName(supTag))
</span><del>-                    result = @&quot;super&quot;;
</del><ins>+                    result = &quot;super&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(subTag))
</span><del>-                    result = @&quot;sub&quot;;
</del><ins>+                    result = &quot;sub&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(theadTag) || coreElement-&gt;hasTagName(tbodyTag) || coreElement-&gt;hasTagName(tfootTag))
</span><del>-                    result = @&quot;middle&quot;;
</del><ins>+                    result = &quot;middle&quot;;
</ins><span class="cx">                 else if (coreElement-&gt;hasTagName(trTag) || coreElement-&gt;hasTagName(thTag) || coreElement-&gt;hasTagName(tdTag))
</span><span class="cx">                     inherit = YES;
</span><span class="cx">             } else if ([@&quot;font-family&quot; isEqualToString:key] || [@&quot;font-variant&quot; isEqualToString:key] || [@&quot;font-effect&quot; isEqualToString:key]
</span><span class="lines">@@ -691,12 +703,14 @@
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">     }
</span><del>-    if (!result &amp;&amp; inherit) {
</del><ins>+    if (!haveResult &amp;&amp; inherit) {
</ins><span class="cx">         DOMNode *parentNode = [node parentNode];
</span><span class="cx">         if (parentNode)
</span><del>-            result = [self _stringForNode:parentNode property:key];
</del><ins>+            return [self _stringForNode:parentNode property:key];
</ins><span class="cx">     }
</span><del>-    return result ? [result lowercaseString] : nil;
</del><ins>+    if (haveResult)
+        return result.lower();
+    return nil;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (NSString *)_stringForNode:(DOMNode *)node property:(NSString *)key
</span><span class="lines">@@ -718,72 +732,82 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static inline bool floatValueFromPrimitiveValue(CSSPrimitiveValue&amp; primitiveValue, float&amp; result)
+{
+    // FIXME: Use CSSPrimitiveValue::computeValue.
+    switch (primitiveValue.primitiveType()) {
+    case CSSPrimitiveValue::CSS_PX:
+        result = primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PX);
+        return true;
+    case CSSPrimitiveValue::CSS_PT:
+        result = 4 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PT) / 3;
+        return true;
+    case CSSPrimitiveValue::CSS_PC:
+        result = 16 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC);
+        return true;
+    case CSSPrimitiveValue::CSS_CM:
+        result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC) / 2.54;
+        return true;
+    case CSSPrimitiveValue::CSS_MM:
+        result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_PC) / 25.4;
+        return true;
+    case CSSPrimitiveValue::CSS_IN:
+        result = 96 * primitiveValue.getFloatValue(CSSPrimitiveValue::CSS_IN);
+        return true;
+    default:
+        return false;
+    }
+}
+
</ins><span class="cx"> static inline BOOL _getFloat(DOMCSSPrimitiveValue *primitiveValue, CGFloat *val)
</span><span class="cx"> {
</span><span class="cx">     if (!val)
</span><span class="cx">         return NO;
</span><del>-    switch ([primitiveValue primitiveType]) {
-        case DOM_CSS_PX:
-            *val = [primitiveValue getFloatValue:DOM_CSS_PX];
-            return YES;
-        case DOM_CSS_PT:
-            *val = 4 * [primitiveValue getFloatValue:DOM_CSS_PT] / 3;
-            return YES;
-        case DOM_CSS_PC:
-            *val = 16 * [primitiveValue getFloatValue:DOM_CSS_PC];
-            return YES;
-        case DOM_CSS_CM:
-            *val = 96 * [primitiveValue getFloatValue:DOM_CSS_CM] / (CGFloat)2.54;
-            return YES;
-        case DOM_CSS_MM:
-            *val = 96 * [primitiveValue getFloatValue:DOM_CSS_MM] / (CGFloat)25.4;
-            return YES;
-        case DOM_CSS_IN:
-            *val = 96 * [primitiveValue getFloatValue:DOM_CSS_IN];
-            return YES;
-        default:
-            return NO;
-    }
</del><ins>+    float result;
+    bool haveResult = floatValueFromPrimitiveValue(*core(primitiveValue), result);
+    if (haveResult &amp;&amp; val)
+        *val = result;
+    return haveResult;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (BOOL)_getComputedFloat:(CGFloat *)val forNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><del>-    BOOL result = NO;
-    BOOL inherit = YES;
-    CGFloat floatVal = 0;
-    DOMElement *element = (DOMElement *)node;    
-    if (element &amp;&amp; [element nodeType] == DOM_ELEMENT_NODE) {
-        DOMCSSStyleDeclaration *computedStyle, *specifiedStyle;
-        inherit = NO;
-        if (!result &amp;&amp; (computedStyle = [self _computedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
-            if (computedValue &amp;&amp; [computedValue cssValueType] == DOM_CSS_PRIMITIVE_VALUE)
-                result = _getFloat(computedValue, &amp;floatVal);
</del><ins>+    bool haveResult = false;
+    bool inherit = true;
+    float floatVal = 0;
+    Node* coreNode = core(node);
+    if (coreNode &amp;&amp; coreNode-&gt;isElementNode()) {
+        Element&amp; element = toElement(*coreNode);
+        String propertyName = key;
+        inherit = false;
+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;computedStylePropertyForElement(element, propertyName)) {
+                if (value-&gt;isPrimitiveValue())
+                    haveResult = floatValueFromPrimitiveValue(toCSSPrimitiveValue(*value), floatVal);
+            }
</ins><span class="cx">         }
</span><del>-        if (!result &amp;&amp; (specifiedStyle = [self _specifiedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
-            if (specifiedValue) {
-                unsigned short valueType = [specifiedValue cssValueType];
-                if (valueType == DOM_CSS_PRIMITIVE_VALUE)
-                    result = _getFloat(specifiedValue, &amp;floatVal);
-                else if (valueType == DOM_CSS_INHERIT)
-                    inherit = YES;
</del><ins>+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;inlineStylePropertyForElement(element, propertyName)) {
+                if (value-&gt;isInheritedValue())
+                    inherit = true;
+                else if (value-&gt;isPrimitiveValue())
+                    haveResult = floatValueFromPrimitiveValue(toCSSPrimitiveValue(*value), floatVal);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><del>-        if (!result) {
</del><ins>+        if (!haveResult) {
</ins><span class="cx">             if ([@&quot;text-indent&quot; isEqualToString:key] || [@&quot;letter-spacing&quot; isEqualToString:key] || [@&quot;word-spacing&quot; isEqualToString:key]
</span><span class="cx">                 || [@&quot;line-height&quot; isEqualToString:key] || [@&quot;widows&quot; isEqualToString:key] || [@&quot;orphans&quot; isEqualToString:key])
</span><del>-                inherit = YES;
</del><ins>+                inherit = true;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><del>-    if (!result &amp;&amp; inherit) {
</del><ins>+    if (!haveResult &amp;&amp; inherit) {
</ins><span class="cx">         DOMNode *parentNode = [node parentNode];
</span><span class="cx">         if (parentNode)
</span><del>-            result = [self _getFloat:&amp;floatVal forNode:parentNode property:key];
</del><ins>+            return [self _getFloat:val forNode:parentNode property:key];
</ins><span class="cx">     }
</span><del>-    if (result &amp;&amp; val)
</del><ins>+    if (haveResult &amp;&amp; val)
</ins><span class="cx">         *val = floatVal;
</span><del>-    return result;
</del><ins>+    return haveResult;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (BOOL)_getFloat:(CGFloat *)val forNode:(DOMNode *)node property:(NSString *)key
</span><span class="lines">@@ -967,41 +991,43 @@
</span><span class="cx"> - (PlatformColor *)_computedColorForNode:(DOMNode *)node property:(NSString *)key
</span><span class="cx"> {
</span><span class="cx">     PlatformColor *result = nil;
</span><del>-    BOOL inherit = YES;
-    BOOL haveResult = NO;
</del><ins>+    bool inherit = true;
+    bool haveResult = false;
</ins><span class="cx">     BOOL isColor = [@&quot;color&quot; isEqualToString:key];
</span><span class="cx">     BOOL isBackgroundColor = [@&quot;background-color&quot; isEqualToString:key];
</span><del>-    DOMElement *element = (DOMElement *)node;    
-    if (element &amp;&amp; [element nodeType] == DOM_ELEMENT_NODE) {
-        DOMCSSStyleDeclaration *computedStyle, *specifiedStyle;
-        inherit = NO;
-        if (!haveResult &amp;&amp; (computedStyle = [self _computedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *computedValue = (DOMCSSPrimitiveValue *)[computedStyle getPropertyCSSValue:key];
-            if (computedValue &amp;&amp; [computedValue cssValueType] == DOM_CSS_PRIMITIVE_VALUE &amp;&amp; [computedValue primitiveType] == DOM_CSS_RGBCOLOR) {
-                result = _colorForRGBColor([computedValue getRGBColorValue], isColor);
-                haveResult = YES;
</del><ins>+    Node* coreNode = core(node);
+    if (coreNode &amp;&amp; coreNode-&gt;isElementNode()) {
+        Element&amp; element = toElement(*coreNode);
+        String propertyName = key;
+        inherit = false;
+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;computedStylePropertyForElement(element, propertyName)) {
+                if (value-&gt;isPrimitiveValue() &amp;&amp; toCSSPrimitiveValue(*value).isRGBColor()) {
+                    RefPtr&lt;WebCore::RGBColor&gt; color = toCSSPrimitiveValue(*value).getRGBColorValue(ASSERT_NO_EXCEPTION);
+                    result = _colorForRGBColor(kit(color.get()), isColor);
+                    haveResult = true;
+                }
</ins><span class="cx">             }
</span><span class="cx">         }
</span><del>-        if (!haveResult &amp;&amp; (specifiedStyle = [self _specifiedStyleForElement:element])) {
-            DOMCSSPrimitiveValue *specifiedValue = (DOMCSSPrimitiveValue *)[specifiedStyle getPropertyCSSValue:key];
-            if (specifiedValue) {
-                unsigned short valueType = [specifiedValue cssValueType];
-                if (valueType == DOM_CSS_PRIMITIVE_VALUE &amp;&amp; [specifiedValue primitiveType] == DOM_CSS_RGBCOLOR) {
-                    result = _colorForRGBColor([specifiedValue getRGBColorValue], isColor);
-                    haveResult = YES;
-                } else if (valueType == DOM_CSS_INHERIT)
-                    inherit = YES;
</del><ins>+        if (!haveResult) {
+            if (RefPtr&lt;CSSValue&gt; value = _caches-&gt;inlineStylePropertyForElement(element, propertyName)) {
+                if (value-&gt;isPrimitiveValue() &amp;&amp; toCSSPrimitiveValue(*value).isRGBColor()) {
+                    RefPtr&lt;WebCore::RGBColor&gt; color = toCSSPrimitiveValue(*value).getRGBColorValue(ASSERT_NO_EXCEPTION);
+                    result = _colorForRGBColor(kit(color.get()), isColor);
+                    haveResult = true;
+                } else if (value-&gt;isInheritedValue())
+                    inherit = true;
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         if (!result) {
</span><del>-            if ((isColor &amp;&amp; !haveResult) || (isBackgroundColor &amp;&amp; ![self _elementHasOwnBackgroundColor:element]))
-                inherit = YES;
</del><ins>+            if ((isColor &amp;&amp; !haveResult) || (isBackgroundColor &amp;&amp; ![self _elementHasOwnBackgroundColor:static_cast&lt;DOMElement*&gt;(node)]))
+                inherit = true;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     if (!result &amp;&amp; inherit) {
</span><span class="cx">         DOMNode *parentNode = [node parentNode];
</span><span class="cx">         if (parentNode &amp;&amp; !(isBackgroundColor &amp;&amp; [parentNode nodeType] == DOM_ELEMENT_NODE &amp;&amp; [self _elementHasOwnBackgroundColor:(DOMElement *)parentNode]))
</span><del>-            result = [self _colorForNode:parentNode property:key];
</del><ins>+            return [self _colorForNode:parentNode property:key];
</ins><span class="cx">     }
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="lines">@@ -2404,7 +2430,6 @@
</span><span class="cx">     [_textTableRows release];
</span><span class="cx">     [_textTableRowArrays release];
</span><span class="cx">     [_textTableRowBackgroundColors release];
</span><del>-    [_computedStylesForElements release];
</del><span class="cx">     [_specifiedStylesForElements release];
</span><span class="cx">     [_stringsForNodes release];
</span><span class="cx">     [_floatsForNodes release];
</span><span class="lines">@@ -2434,7 +2459,6 @@
</span><span class="cx">     _textTableRows = [[NSMutableArray alloc] init];
</span><span class="cx">     _textTableRowArrays = [[NSMutableArray alloc] init];
</span><span class="cx">     _textTableRowBackgroundColors = [[NSMutableArray alloc] init];
</span><del>-    _computedStylesForElements = [[NSMutableDictionary alloc] init];
</del><span class="cx">     _specifiedStylesForElements = [[NSMutableDictionary alloc] init];
</span><span class="cx">     _stringsForNodes = [[NSMutableDictionary alloc] init];
</span><span class="cx">     _floatsForNodes = [[NSMutableDictionary alloc] init];
</span><span class="lines">@@ -2452,6 +2476,8 @@
</span><span class="cx">     _errorCode = -1;
</span><span class="cx">     _indexingLimit = 0;
</span><span class="cx">     _thumbnailLimit = 0;
</span><ins>+    
+    _caches = std::make_unique&lt;HTMLConverterCaches&gt;();
</ins><span class="cx"> 
</span><span class="cx">     _flags.isIndexing = (_indexingLimit &gt; 0);
</span><span class="cx">     _flags.isTesting = 0;
</span></span></pre>
</div>
</div>

</body>
</html>