Ignore:
Timestamp:
Feb 11, 2013, 3:00:54 AM (12 years ago)
Author:
[email protected]
Message:

Implement CSSValue::equals(const CSSValue&) to optimise CSSValue comparison
https://bugs.webkit.org/show_bug.cgi?id=102901

Patch by Alexander Shalamov <[email protected]> on 2013-02-11
Reviewed by Antti Koivisto.

Source/WebCore:

Added comparison method to CSSValue and its children, so that the
css values could be compared efficiently. Before this patch, CSSValue
objects were compared using strings that were generated by the cssText() method.

Test: cssom/cssvalue-comparison.html

  • css/CSSAspectRatioValue.cpp:

(WebCore::CSSAspectRatioValue::equals):
(WebCore):

  • css/CSSAspectRatioValue.h:

(CSSAspectRatioValue):

  • css/CSSBasicShapes.cpp:

(WebCore::CSSBasicShapeRectangle::equals):
(WebCore):
(WebCore::CSSBasicShapeCircle::equals):
(WebCore::CSSBasicShapeEllipse::equals):
(WebCore::CSSBasicShapePolygon::equals):

  • css/CSSBasicShapes.h:

(CSSBasicShapeRectangle):
(CSSBasicShapeCircle):
(CSSBasicShapeEllipse):
(CSSBasicShapePolygon):

  • css/CSSBorderImageSliceValue.cpp:

(WebCore::CSSBorderImageSliceValue::equals):
(WebCore):

  • css/CSSBorderImageSliceValue.h:

(CSSBorderImageSliceValue):

  • css/CSSCalculationValue.cpp:

(WebCore::CSSCalcValue::equals):
(WebCore):
(WebCore::CSSCalcPrimitiveValue::equals):
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcPrimitiveValue::type):
(WebCore::CSSCalcBinaryOperation::equals):
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::type):

  • css/CSSCalculationValue.h:

(WebCore::CSSCalcExpressionNode::equals):
(CSSCalcExpressionNode):
(CSSCalcValue):

  • css/CSSCanvasValue.cpp:

(WebCore::CSSCanvasValue::equals):
(WebCore):

  • css/CSSCanvasValue.h:

(CSSCanvasValue):

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSComputedStyleDeclaration::cssPropertyMatches):
(WebCore::CSSComputedStyleDeclaration::getCSSPropertyValuesForSidesShorthand):

  • css/CSSCrossfadeValue.cpp:

(WebCore::CSSCrossfadeValue::equals):
(WebCore):

  • css/CSSCrossfadeValue.h:

(CSSCrossfadeValue):

  • css/CSSCursorImageValue.cpp:

(WebCore::CSSCursorImageValue::equals):
(WebCore):

  • css/CSSCursorImageValue.h:

(CSSCursorImageValue):

  • css/CSSFontFaceSrcValue.cpp:

(WebCore::CSSFontFaceSrcValue::equals):
(WebCore):

  • css/CSSFontFaceSrcValue.h:

(CSSFontFaceSrcValue):

  • css/CSSFunctionValue.cpp:

(WebCore::CSSFunctionValue::equals):
(WebCore):

  • css/CSSFunctionValue.h:

(CSSFunctionValue):

  • css/CSSGradientValue.cpp:

(WebCore::CSSLinearGradientValue::equals):
(WebCore):
(WebCore::CSSRadialGradientValue::equals):

  • css/CSSGradientValue.h:

(WebCore::CSSGradientColorStop::operator==):
(CSSLinearGradientValue):
(CSSRadialGradientValue):

  • css/CSSImageValue.cpp:

(WebCore::CSSImageValue::equals):
(WebCore):

  • css/CSSImageValue.h:

(CSSImageValue):

  • css/CSSInheritedValue.h:

(WebCore::CSSInheritedValue::equals):
(CSSInheritedValue):

  • css/CSSInitialValue.h:

(WebCore::CSSInitialValue::equals):
(CSSInitialValue):

  • css/CSSLineBoxContainValue.h:

(WebCore::CSSLineBoxContainValue::equals):

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::equals):
(WebCore):

  • css/CSSPrimitiveValue.h:

(CSSPrimitiveValue):

  • css/CSSReflectValue.cpp:

(WebCore::CSSReflectValue::equals):
(WebCore):

  • css/CSSReflectValue.h:

(CSSReflectValue):

  • css/CSSTimingFunctionValue.cpp:

(WebCore::CSSCubicBezierTimingFunctionValue::equals):
(WebCore):
(WebCore::CSSStepsTimingFunctionValue::equals):

  • css/CSSTimingFunctionValue.h:

(WebCore::CSSLinearTimingFunctionValue::equals):
(CSSLinearTimingFunctionValue):
(CSSCubicBezierTimingFunctionValue):
(CSSStepsTimingFunctionValue):

  • css/CSSUnicodeRangeValue.cpp:

(WebCore::CSSUnicodeRangeValue::equals):
(WebCore):

  • css/CSSUnicodeRangeValue.h:

(CSSUnicodeRangeValue):

  • css/CSSValue.cpp:

(WebCore):
(WebCore::compareCSSValues):
(WebCore::CSSValue::equals):

  • css/CSSValue.h:

(CSSValue):
(WebCore):
(WebCore::compareCSSValueVector):
(WebCore::compareCSSValuePtr):

  • css/CSSValueList.cpp:

(WebCore::CSSValueList::removeAll):
(WebCore::CSSValueList::hasValue):
(WebCore::CSSValueList::equals):
(WebCore):

  • css/CSSValueList.h:

(CSSValueList):

  • css/CSSVariableValue.h:

(WebCore::CSSVariableValue::equals):
(CSSVariableValue):

  • css/Counter.h:

(Counter):
(WebCore::Counter::equals):

  • css/DashboardRegion.h:

(WebCore::DashboardRegion::equals):

  • css/FontFeatureValue.cpp:

(WebCore::FontFeatureValue::equals):
(WebCore):

  • css/FontFeatureValue.h:

(FontFeatureValue):

  • css/FontValue.cpp:

(WebCore::FontValue::equals):
(WebCore):

  • css/FontValue.h:

(FontValue):

  • css/MediaQueryExp.h:

(WebCore::MediaQueryExp::operator==):

  • css/Pair.h:

(WebCore::Pair::equals):
(Pair):

  • css/Rect.h:

(WebCore::RectBase::equals):
(RectBase):

  • css/ShadowValue.cpp:

(WebCore::ShadowValue::equals):
(WebCore):

  • css/ShadowValue.h:

(ShadowValue):

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::get4Values):
(WebCore::StylePropertySet::propertyMatches):

  • css/WebKitCSSArrayFunctionValue.cpp:

(WebCore::WebKitCSSArrayFunctionValue::equals):
(WebCore):

  • css/WebKitCSSArrayFunctionValue.h:

(WebKitCSSArrayFunctionValue):

  • css/WebKitCSSFilterValue.cpp:

(WebCore::WebKitCSSFilterValue::equals):
(WebCore):

  • css/WebKitCSSFilterValue.h:

(WebKitCSSFilterValue):

  • css/WebKitCSSMixFunctionValue.cpp:

(WebCore::WebKitCSSMixFunctionValue::equals):
(WebCore):

  • css/WebKitCSSMixFunctionValue.h:

(WebKitCSSMixFunctionValue):

  • css/WebKitCSSSVGDocumentValue.cpp:

(WebCore::WebKitCSSSVGDocumentValue::equals):
(WebCore):

  • css/WebKitCSSSVGDocumentValue.h:

(WebKitCSSSVGDocumentValue):

  • css/WebKitCSSShaderValue.cpp:

(WebCore::WebKitCSSShaderValue::equals):
(WebCore):

  • css/WebKitCSSShaderValue.h:

(WebKitCSSShaderValue):

  • css/WebKitCSSTransformValue.h:

(WebCore::WebKitCSSTransformValue::equals):

  • editing/EditingStyle.cpp:

(WebCore::HTMLAttributeEquivalent::valueIsPresentInStyle):

  • svg/SVGColor.cpp:

(WebCore::SVGColor::equals):
(WebCore):

  • svg/SVGColor.h:

(SVGColor):

  • svg/SVGPaint.cpp:

(WebCore::SVGPaint::equals):
(WebCore):

  • svg/SVGPaint.h:

(SVGPaint):

LayoutTests:

New layout test to verify that CSSValue objects comparison works properly.

  • cssom/cssvalue-comparison-expected.txt: Added.
  • cssom/cssvalue-comparison.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r141637 r142444  
    724724}
    725725
     726bool CSSLinearGradientValue::equals(const CSSLinearGradientValue& other) const
     727{
     728    if (m_gradientType == CSSDeprecatedLinearGradient)
     729        return other.m_gradientType == m_gradientType
     730            && compareCSSValuePtr(m_firstX, other.m_firstX)
     731            && compareCSSValuePtr(m_firstY, other.m_firstY)
     732            && compareCSSValuePtr(m_secondX, other.m_secondX)
     733            && compareCSSValuePtr(m_secondY, other.m_secondY)
     734            && m_stops == other.m_stops;
     735
     736    if (m_repeating != other.m_repeating)
     737        return false;
     738
     739    if (m_angle)
     740        return compareCSSValuePtr(m_angle, other.m_angle) && m_stops == other.m_stops;
     741
     742    if (other.m_angle)
     743        return false;
     744
     745    bool equalXorY = false;
     746    if (m_firstX && m_firstY)
     747        equalXorY = compareCSSValuePtr(m_firstX, other.m_firstX) && compareCSSValuePtr(m_firstY, other.m_firstY);
     748    else if (m_firstX)
     749        equalXorY =compareCSSValuePtr(m_firstX, other.m_firstX) && !other.m_firstY;
     750    else if (m_firstY)
     751        equalXorY = compareCSSValuePtr(m_firstY, other.m_firstY) && !other.m_firstX;
     752    else
     753        equalXorY = !other.m_firstX || !other.m_firstY;
     754
     755    return equalXorY && m_stops == other.m_stops;
     756}
     757
    726758void CSSLinearGradientValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
    727759{
     
    11131145}
    11141146
     1147bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const
     1148{
     1149    if (m_gradientType == CSSDeprecatedRadialGradient)
     1150        return other.m_gradientType == m_gradientType
     1151            && compareCSSValuePtr(m_firstX, other.m_firstX)
     1152            && compareCSSValuePtr(m_firstY, other.m_firstY)
     1153            && compareCSSValuePtr(m_secondX, other.m_secondX)
     1154            && compareCSSValuePtr(m_secondY, other.m_secondY)
     1155            && compareCSSValuePtr(m_firstRadius, other.m_firstRadius)
     1156            && compareCSSValuePtr(m_secondRadius, other.m_secondRadius)
     1157            && m_stops == other.m_stops;
     1158
     1159    if (m_repeating != other.m_repeating)
     1160        return false;
     1161
     1162    bool equalXorY = false;
     1163    if (m_firstX && m_firstY)
     1164        equalXorY = compareCSSValuePtr(m_firstX, other.m_firstX) && compareCSSValuePtr(m_firstY, other.m_firstY);
     1165    else if (m_firstX)
     1166        equalXorY = compareCSSValuePtr(m_firstX, other.m_firstX) && !other.m_firstY;
     1167    else if (m_firstY)
     1168        equalXorY = compareCSSValuePtr(m_firstY, other.m_firstY) && !other.m_firstX;
     1169    else
     1170        equalXorY == !other.m_firstX || !other.m_firstY;
     1171
     1172    if (!equalXorY)
     1173        return false;
     1174
     1175    bool equalShape = true;
     1176    bool equalSizingBehavior = true;
     1177    bool equalHorizontalAndVerticalSize = true;
     1178
     1179    if (m_shape)
     1180        equalShape = compareCSSValuePtr(m_shape, other.m_shape);
     1181    else if (m_sizingBehavior)
     1182        equalSizingBehavior = compareCSSValuePtr(m_sizingBehavior, other.m_sizingBehavior);
     1183    else if (m_endHorizontalSize && m_endVerticalSize)
     1184        equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize, other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_endVerticalSize);
     1185    else {
     1186        equalShape = !other.m_shape;
     1187        equalSizingBehavior = !other.m_sizingBehavior;
     1188        equalHorizontalAndVerticalSize = !other.m_endHorizontalSize && !other.m_endVerticalSize;
     1189    }
     1190    return equalShape && equalSizingBehavior && equalHorizontalAndVerticalSize && m_stops == other.m_stops;
     1191}
     1192
    11151193void CSSRadialGradientValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
    11161194{
Note: See TracChangeset for help on using the changeset viewer.