Chromium Code Reviews| Index: Source/core/dom/shadow/SelectRuleFeatureSet.cpp |
| diff --git a/Source/core/dom/shadow/SelectRuleFeatureSet.cpp b/Source/core/dom/shadow/SelectRuleFeatureSet.cpp |
| index 02ab9488fc36a42faff5c91c7eaf4845f0efe419..25757e6bc7463c69a3e5cbe978cbf07cabbe35e9 100644 |
| --- a/Source/core/dom/shadow/SelectRuleFeatureSet.cpp |
| +++ b/Source/core/dom/shadow/SelectRuleFeatureSet.cpp |
| @@ -33,6 +33,8 @@ |
| #include "core/css/CSSSelector.h" |
| +#include "wtf/BitVector.h" |
| + |
| namespace WebCore { |
| SelectRuleFeatureSet::SelectRuleFeatureSet() |
| @@ -83,5 +85,53 @@ void SelectRuleFeatureSet::collectFeaturesFromSelector(const CSSSelector& select |
| } |
| } |
| +bool SelectRuleFeatureSet::checkSelectorsForClassChange(const SpaceSplitString& changedClasses) const |
| +{ |
| + unsigned changedSize = changedClasses.size(); |
| + for (unsigned i = 0; i < changedSize; ++i) { |
| + if (hasSelectorForClass(changedClasses[i])) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +bool SelectRuleFeatureSet::checkSelectorsForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses) const |
|
ojan
2014/01/30 19:08:39
It's a bummer there's so much copy-paste between t
chrishtr
2014/01/30 19:25:48
Agreed. I tried several approaches, but all turned
|
| +{ |
| + if (!oldClasses.size()) |
| + return checkSelectorsForClassChange(newClasses); |
| + |
| + // Class vectors tend to be very short. This is faster than using a hash table. |
| + BitVector remainingClassBits; |
| + remainingClassBits.ensureSize(oldClasses.size()); |
| + |
| + for (unsigned i = 0; i < newClasses.size(); ++i) { |
| + bool found = false; |
| + for (unsigned j = 0; j < oldClasses.size(); ++j) { |
| + if (newClasses[i] == oldClasses[j]) { |
| + // Mark each class that is still in the newClasses so we can skip doing |
| + // an n^2 search below when looking for removals. We can't break from |
| + // this loop early since a class can appear more than once. |
| + remainingClassBits.quickSet(j); |
| + found = true; |
| + } |
| + } |
| + // Class was added. |
| + if (!found) { |
| + if (hasSelectorForClass(newClasses[i])) |
| + return true; |
| + } |
| + } |
| + |
| + for (unsigned i = 0; i < oldClasses.size(); ++i) { |
| + if (remainingClassBits.quickGet(i)) |
| + continue; |
| + |
| + // Class was removed. |
| + if (hasSelectorForClass(oldClasses[i])) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| } |