Skip to content

Commit

Permalink
Remove rule ranges in MatchResult
Browse files Browse the repository at this point in the history
They are no longer used by anything.

Change-Id: Ibdfc66e8bc30841fc01292ca5961ecf522588c84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310496
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791180}
  • Loading branch information
andruud authored and Commit Bot committed Jul 23, 2020
1 parent 7a2c0ab commit cfab2fd
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 218 deletions.
23 changes: 0 additions & 23 deletions third_party/blink/renderer/core/css/resolver/match_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,16 @@ void MatchResult::AddMatchedProperties(
void MatchResult::FinishAddingUARules() {
DCHECK_EQ(current_origin_, CascadeOrigin::kUserAgent);
current_origin_ = CascadeOrigin::kUser;
ua_range_end_ = matched_properties_.size();
}

void MatchResult::FinishAddingUserRules() {
DCHECK_EQ(current_origin_, CascadeOrigin::kUser);
current_origin_ = CascadeOrigin::kAuthor;
// Don't add empty ranges.
if (user_range_ends_.IsEmpty() &&
ua_range_end_ == matched_properties_.size())
return;
if (!user_range_ends_.IsEmpty() &&
user_range_ends_.back() == matched_properties_.size())
return;
user_range_ends_.push_back(matched_properties_.size());
}

void MatchResult::FinishAddingAuthorRulesForTreeScope() {
DCHECK_EQ(current_origin_, CascadeOrigin::kAuthor);
current_tree_order_ = base::ClampAdd(current_tree_order_, 1);
// Don't add empty ranges.
if (author_range_ends_.IsEmpty() && user_range_ends_.IsEmpty() &&
ua_range_end_ == matched_properties_.size())
return;
if (author_range_ends_.IsEmpty() && !user_range_ends_.IsEmpty() &&
user_range_ends_.back() == matched_properties_.size())
return;
if (!author_range_ends_.IsEmpty() &&
author_range_ends_.back() == matched_properties_.size())
return;
author_range_ends_.push_back(matched_properties_.size());
}

MatchedExpansionsRange MatchResult::Expansions(const Document& document,
Expand All @@ -109,9 +89,6 @@ MatchedExpansionsRange MatchResult::Expansions(const Document& document,

void MatchResult::Reset() {
matched_properties_.clear();
user_range_ends_.clear();
author_range_ends_.clear();
ua_range_end_ = 0;
is_cacheable_ = true;
current_origin_ = CascadeOrigin::kUserAgent;
current_tree_order_ = 0;
Expand Down
53 changes: 0 additions & 53 deletions third_party/blink/renderer/core/css/resolver/match_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,6 @@ namespace blink {

using MatchedPropertiesVector = HeapVector<MatchedProperties, 64>;

// MatchedPropertiesRange is used to represent a subset of the matched
// properties from a given origin, for instance UA rules, author rules, or a
// shadow tree scope. This is needed because rules from different origins are
// applied in the opposite order for !important rules, yet in the same order as
// for normal rules within the same origin.

class MatchedPropertiesRange {
public:
MatchedPropertiesRange(MatchedPropertiesVector::const_iterator begin,
MatchedPropertiesVector::const_iterator end)
: begin_(begin), end_(end) {}

MatchedPropertiesVector::const_iterator begin() const { return begin_; }
MatchedPropertiesVector::const_iterator end() const { return end_; }

bool IsEmpty() const { return begin() == end(); }

private:
MatchedPropertiesVector::const_iterator begin_;
MatchedPropertiesVector::const_iterator end_;
};

class MatchedExpansionsIterator {
STACK_ALLOCATED();
using Iterator = MatchedPropertiesVector::const_iterator;
Expand Down Expand Up @@ -168,34 +146,6 @@ class CORE_EXPORT MatchResult {

MatchedExpansionsRange Expansions(const Document&, CascadeFilter) const;

MatchedPropertiesRange AllRules() const {
return MatchedPropertiesRange(matched_properties_.begin(),
matched_properties_.end());
}
MatchedPropertiesRange UaRules() const {
MatchedPropertiesVector::const_iterator begin = matched_properties_.begin();
MatchedPropertiesVector::const_iterator end =
matched_properties_.begin() + ua_range_end_;
return MatchedPropertiesRange(begin, end);
}
MatchedPropertiesRange UserRules() const {
MatchedPropertiesVector::const_iterator begin =
matched_properties_.begin() + ua_range_end_;
MatchedPropertiesVector::const_iterator end =
matched_properties_.begin() + (user_range_ends_.IsEmpty()
? ua_range_end_
: user_range_ends_.back());
return MatchedPropertiesRange(begin, end);
}
MatchedPropertiesRange AuthorRules() const {
MatchedPropertiesVector::const_iterator begin =
matched_properties_.begin() + (user_range_ends_.IsEmpty()
? ua_range_end_
: user_range_ends_.back());
MatchedPropertiesVector::const_iterator end = matched_properties_.end();
return MatchedPropertiesRange(begin, end);
}

const MatchedPropertiesVector& GetMatchedProperties() const {
return matched_properties_;
}
Expand All @@ -206,9 +156,6 @@ class CORE_EXPORT MatchResult {

private:
MatchedPropertiesVector matched_properties_;
Vector<unsigned, 16> user_range_ends_;
Vector<unsigned, 16> author_range_ends_;
unsigned ua_range_end_ = 0;
bool is_cacheable_ = true;
CascadeOrigin current_origin_ = CascadeOrigin::kUserAgent;
uint16_t current_tree_order_ = 0;
Expand Down
142 changes: 0 additions & 142 deletions third_party/blink/renderer/core/css/resolver/match_result_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,148 +44,6 @@ void MatchResultTest::SetUp() {
}
}

void TestMatchedPropertiesRange(const MatchedPropertiesRange& range,
int expected_length,
const CSSPropertyValueSet** expected_sets) {
EXPECT_EQ(expected_length, range.end() - range.begin());
for (const auto& matched_properties : range)
EXPECT_EQ(*expected_sets++, matched_properties.properties);
}

TEST_F(MatchResultTest, UARules) {
const CSSPropertyValueSet* ua_sets[] = {PropertySet(0), PropertySet(1)};

MatchResult result;
result.AddMatchedProperties(ua_sets[0]);
result.AddMatchedProperties(ua_sets[1]);
result.FinishAddingUARules();
result.FinishAddingUserRules();

result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 2, ua_sets);
TestMatchedPropertiesRange(result.UaRules(), 2, ua_sets);
TestMatchedPropertiesRange(result.UserRules(), 0, nullptr);
TestMatchedPropertiesRange(result.AuthorRules(), 0, nullptr);
}

TEST_F(MatchResultTest, UserRules) {
const CSSPropertyValueSet* user_sets[] = {PropertySet(0), PropertySet(1)};

MatchResult result;

result.FinishAddingUARules();
result.AddMatchedProperties(user_sets[0]);
result.AddMatchedProperties(user_sets[1]);
result.FinishAddingUserRules();
result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 2, user_sets);
TestMatchedPropertiesRange(result.UaRules(), 0, nullptr);
TestMatchedPropertiesRange(result.UserRules(), 2, user_sets);
TestMatchedPropertiesRange(result.AuthorRules(), 0, nullptr);
}

TEST_F(MatchResultTest, AuthorRules) {
const CSSPropertyValueSet* author_sets[] = {PropertySet(0), PropertySet(1)};

MatchResult result;

result.FinishAddingUARules();
result.FinishAddingUserRules();
result.AddMatchedProperties(author_sets[0]);
result.AddMatchedProperties(author_sets[1]);
result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 2, author_sets);
TestMatchedPropertiesRange(result.UaRules(), 0, nullptr);
TestMatchedPropertiesRange(result.UserRules(), 0, nullptr);
TestMatchedPropertiesRange(result.AuthorRules(), 2, author_sets);
}

TEST_F(MatchResultTest, AllRules) {
const CSSPropertyValueSet* all_sets[] = {PropertySet(0), PropertySet(1),
PropertySet(2), PropertySet(3),
PropertySet(4), PropertySet(5)};
const CSSPropertyValueSet** ua_sets = &all_sets[0];
const CSSPropertyValueSet** user_sets = &all_sets[2];
const CSSPropertyValueSet** author_sets = &all_sets[4];

MatchResult result;

result.AddMatchedProperties(ua_sets[0]);
result.AddMatchedProperties(ua_sets[1]);
result.FinishAddingUARules();

result.AddMatchedProperties(user_sets[0]);
result.AddMatchedProperties(user_sets[1]);
result.FinishAddingUserRules();

result.AddMatchedProperties(author_sets[0]);
result.AddMatchedProperties(author_sets[1]);
result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 6, all_sets);
TestMatchedPropertiesRange(result.UaRules(), 2, ua_sets);
TestMatchedPropertiesRange(result.UserRules(), 2, user_sets);
TestMatchedPropertiesRange(result.AuthorRules(), 2, author_sets);
}

TEST_F(MatchResultTest, AuthorRulesMultipleScopes) {
const CSSPropertyValueSet* author_sets[] = {PropertySet(0), PropertySet(1),
PropertySet(2), PropertySet(3)};

MatchResult result;

result.FinishAddingUARules();
result.FinishAddingUserRules();

result.AddMatchedProperties(author_sets[0]);
result.AddMatchedProperties(author_sets[1]);
result.FinishAddingAuthorRulesForTreeScope();

result.AddMatchedProperties(author_sets[2]);
result.AddMatchedProperties(author_sets[3]);
result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 4, author_sets);
TestMatchedPropertiesRange(result.UaRules(), 0, nullptr);
TestMatchedPropertiesRange(result.UserRules(), 0, nullptr);
TestMatchedPropertiesRange(result.AuthorRules(), 4, author_sets);
}

TEST_F(MatchResultTest, AllRulesMultipleScopes) {
const CSSPropertyValueSet* all_sets[] = {
PropertySet(0), PropertySet(1), PropertySet(2), PropertySet(3),
PropertySet(4), PropertySet(5), PropertySet(6), PropertySet(7)};
const CSSPropertyValueSet** ua_sets = &all_sets[0];
const CSSPropertyValueSet** user_sets = &all_sets[2];
const CSSPropertyValueSet** author_sets = &all_sets[4];

MatchResult result;

result.AddMatchedProperties(ua_sets[0]);
result.AddMatchedProperties(ua_sets[1]);
result.FinishAddingUARules();

result.AddMatchedProperties(user_sets[0]);
result.AddMatchedProperties(user_sets[1]);
result.FinishAddingUserRules();

result.AddMatchedProperties(author_sets[0]);
result.AddMatchedProperties(author_sets[1]);
result.FinishAddingAuthorRulesForTreeScope();

result.AddMatchedProperties(author_sets[2]);
result.AddMatchedProperties(author_sets[3]);
result.FinishAddingAuthorRulesForTreeScope();

TestMatchedPropertiesRange(result.AllRules(), 8, all_sets);
TestMatchedPropertiesRange(result.UaRules(), 2, ua_sets);
TestMatchedPropertiesRange(result.UserRules(), 2, user_sets);
TestMatchedPropertiesRange(result.AuthorRules(), 4, author_sets);
}

TEST_F(MatchResultTest, CascadeOriginUserAgent) {
MatchResult result;
result.AddMatchedProperties(PropertySet(0));
Expand Down

0 comments on commit cfab2fd

Please sign in to comment.