[webkit-changes] [WebKit/WebKit] 9adcbe: Refactor the code that handles selector specificit...

Darin Adler noreply at github.com
Wed Nov 16 21:33:13 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9adcbe8f12b9c117447569ca9d6e1cc28d934ae8
      https://github.com/WebKit/WebKit/commit/9adcbe8f12b9c117447569ca9d6e1cc28d934ae8
  Author: Darin Adler <darin at apple.com>
  Date:   2022-11-16 (Wed, 16 Nov 2022)

  Changed paths:
    M Source/WebCore/css/CSSSelector.cpp
    M Source/WebCore/css/CSSSelector.h
    M Source/WebCore/inspector/InspectorStyleSheet.cpp

  Log Message:
  -----------
  Refactor the code that handles selector specificity for simplicity and remove unused functions
https://bugs.webkit.org/show_bug.cgi?id=247851
rdar://problem/102281644

Reviewed by Sam Weinig.

* Source/WebCore/css/CSSSelector.cpp:
(WebCore::CSSSelector::CSSSelector): Removed the m_ prefixes from struct members.
(WebCore::CSSSelector::createRareData): Get rid of the local AtomString here. Clearer without.
(WebCore::SelectorSpecificity): Added a struct to wrap a selector specificity value, so we can
convert from the enum without a static_cast and use the + and += operators for saturating
addition of each channel in parallel.
(WebCore::SelectorSpecificity::operator+=): Implemented. Replaces addSpecificities.
(WebCore::operator+): Implemented by calling +=.
(WebCore::selectorSpecificity): Use SelectorSpecificity.
(WebCore::maxSpecificity): Ditto. Also changed to take a pointer and check for null since that
simplifies the code below.
(WebCore::simpleSelectorSpecificity): Renamed from simpleSelectorSpecificityInternal and changed
the return value to SelectorSpecificity. Removed now-unneeded static_cast and use + instead of
CSSSelector::addSpecificities.
(WebCore::CSSSelector::simpleSelectorSpecificity const): Deleted.
(WebCore::CSSSelector::computeSpecificity const): Updated for SelectorSpecificity.
(WebCore::CSSSelector::computeSpecificityTuple const): Added. This is for the inspector code
that wants the three different components of specifity as separate integers.
(WebCore::CSSSelector::addSpecificities): Deleted.
(WebCore::appendPseudoClassFunctionTail): Removed the m_ prefixes from struct members.
(WebCore::CSSSelector::setAttribute): Ditto.
(WebCore::CSSSelector::setArgument): Ditto.
(WebCore::CSSSelector::setArgumentList): Ditto.
(WebCore::CSSSelector::setSelectorList): Ditto.
(WebCore::CSSSelector::setNth): Ditto.
(WebCore::CSSSelector::matchNth const): Ditto.
(WebCore::CSSSelector::nthA const): Ditto.
(WebCore::CSSSelector::nthB const): Ditto.
(WebCore::CSSSelector::RareData::RareData): Use WTFMove to eliminate a bit of reference count
churn. Moved more initialization to the class definition.
(WebCore::CSSSelector::RareData::create): Moved here from the header, since this is only called
from inside this file. Changed argument type to just AtomString, which is still compatible with
moving new values in and more straightforward.
(WebCore::CSSSelector::RareData::matchNth): Removed the m_ prefixes from struct members.

* Source/WebCore/css/CSSSelector.h: Removed idMask, classMask, simpleSelectorSpecificity, and
addSpecificities, none of which are needed outside the class. Added computeSpecificityTuple
for use by the inspector. Changed struct members to not use the m_ syntax; we do that for
private class members, not struct members. Updated the RareData::create function and initialized
a, and b in RareData.

* Source/WebCore/inspector/InspectorStyleSheet.cpp:
(WebCore::buildObjectForSelectorHelper): Use computeSpecificityTuple.

Canonical link: https://commits.webkit.org/256769@main




More information about the webkit-changes mailing list