Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: third_party/WebKit/Source/core/css/ActiveStyleSheets.cpp

Issue 1889993002: Implemented RuleSet diff for active stylesheets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/css/ActiveStyleSheets.h"
6
7 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/RuleSet.h"
9
10 namespace blink {
11
12 ActiveSheetsChange compareActiveStyleSheets(const ActiveStyleSheetVector& oldSty leSheets,
13 const ActiveStyleSheetVector& newStyleSheets,
14 HeapVector<Member<RuleSet>>& changedRuleSets)
15 {
16 unsigned newStyleSheetCount = newStyleSheets.size();
17 unsigned oldStyleSheetCount = oldStyleSheets.size();
18
19 unsigned minCount = std::min(newStyleSheetCount, oldStyleSheetCount);
20 unsigned index = 0;
21
22 // Walk the common prefix of stylesheets. If the stylesheet rules were
23 // modified since last time, add them to the list of changed rulesets.
24 for (; index < minCount && newStyleSheets[index].first == oldStyleSheets[ind ex].first; index++) {
25 if (newStyleSheets[index].second == oldStyleSheets[index].second)
26 continue;
27
28 changedRuleSets.append(newStyleSheets[index].second);
29 changedRuleSets.append(oldStyleSheets[index].second);
30 }
31
32 if (index == oldStyleSheetCount) {
33 if (index == newStyleSheetCount)
34 return changedRuleSets.size() ? ActiveSheetsChanged : NoActiveSheets Changed;
35
36 // Sheets added at the end.
37 for (; index < newStyleSheetCount; index++)
38 changedRuleSets.append(newStyleSheets[index].second);
39 return ActiveSheetsAppended;
40 }
41
42 if (index == newStyleSheetCount) {
43 // Sheets removed from the end.
44 for (; index < oldStyleSheetCount; index++)
45 changedRuleSets.append(oldStyleSheets[index].second);
46 return ActiveSheetsChanged;
47 }
48
49 DCHECK(index < oldStyleSheetCount && index < newStyleSheetCount);
50
51 // Both the new and old active stylesheet vectors have stylesheets following
52 // the common prefix. Figure out which were added or removed by sorting the
53 // merged vector of old and new sheets.
54
55 ActiveStyleSheetVector mergedSorted;
56 mergedSorted.reserveCapacity(oldStyleSheetCount + newStyleSheetCount - 2 * i ndex);
57 mergedSorted.appendRange(oldStyleSheets.begin() + index, oldStyleSheets.end( ));
58 mergedSorted.appendRange(newStyleSheets.begin() + index, newStyleSheets.end( ));
59
60 std::sort(mergedSorted.begin(), mergedSorted.end());
61
62 auto mergedIterator = mergedSorted.begin();
63 while (mergedIterator != mergedSorted.end()) {
64
65 const auto& sheet1 = *mergedIterator++;
66 if (mergedIterator == mergedSorted.end() || (*mergedIterator).first != s heet1.first) {
67 // Sheet either removed or inserted.
68 changedRuleSets.append(sheet1.second);
69 continue;
70 }
71
72 // Sheet present in both old and new.
73 const auto& sheet2 = *mergedIterator++;
74
75 if (sheet1.second == sheet2.second)
76 continue;
77
78 // Active rules for the given stylesheet changed.
79 // DOM, CSSOM, or media query changes.
80 changedRuleSets.append(sheet1.second);
81 changedRuleSets.append(sheet2.second);
82 }
83 return ActiveSheetsChanged;
84 }
85
86 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/ActiveStyleSheets.h ('k') | third_party/WebKit/Source/core/css/ActiveStyleSheetsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698