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

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

Issue 2654033007: Migrate WTF::HashSet::add() to ::insert() [part 2 of N] (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/ActiveStyleSheets.h" 5 #include "core/css/ActiveStyleSheets.h"
6 6
7 #include "core/css/CSSStyleSheet.h" 7 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/RuleSet.h" 8 #include "core/css/RuleSet.h"
9 #include "core/css/resolver/ScopedStyleResolver.h" 9 #include "core/css/resolver/ScopedStyleResolver.h"
10 #include "core/dom/ContainerNode.h" 10 #include "core/dom/ContainerNode.h"
(...skipping 26 matching lines...) Expand all
37 changedRuleSets.insert(oldStyleSheets[index].second); 37 changedRuleSets.insert(oldStyleSheets[index].second);
38 } 38 }
39 39
40 if (index == oldStyleSheetCount) { 40 if (index == oldStyleSheetCount) {
41 // The old stylesheet vector is a prefix of the new vector in terms of 41 // The old stylesheet vector is a prefix of the new vector in terms of
42 // StyleSheets. If none of the RuleSets changed, we only need to add the new 42 // StyleSheets. If none of the RuleSets changed, we only need to add the new
43 // sheets to the ScopedStyleResolver (ActiveSheetsAppended). 43 // sheets to the ScopedStyleResolver (ActiveSheetsAppended).
44 bool ruleSetsChangedInCommonPrefix = !changedRuleSets.isEmpty(); 44 bool ruleSetsChangedInCommonPrefix = !changedRuleSets.isEmpty();
45 for (; index < newStyleSheetCount; index++) { 45 for (; index < newStyleSheetCount; index++) {
46 if (newStyleSheets[index].second) 46 if (newStyleSheets[index].second)
47 changedRuleSets.add(newStyleSheets[index].second); 47 changedRuleSets.insert(newStyleSheets[index].second);
48 } 48 }
49 if (ruleSetsChangedInCommonPrefix) 49 if (ruleSetsChangedInCommonPrefix)
50 return ActiveSheetsChanged; 50 return ActiveSheetsChanged;
51 if (changedRuleSets.isEmpty()) 51 if (changedRuleSets.isEmpty())
52 return NoActiveSheetsChanged; 52 return NoActiveSheetsChanged;
53 return ActiveSheetsAppended; 53 return ActiveSheetsAppended;
54 } 54 }
55 55
56 if (index == newStyleSheetCount) { 56 if (index == newStyleSheetCount) {
57 // Sheets removed from the end. 57 // Sheets removed from the end.
58 for (; index < oldStyleSheetCount; index++) { 58 for (; index < oldStyleSheetCount; index++) {
59 if (oldStyleSheets[index].second) 59 if (oldStyleSheets[index].second)
60 changedRuleSets.add(oldStyleSheets[index].second); 60 changedRuleSets.insert(oldStyleSheets[index].second);
61 } 61 }
62 return changedRuleSets.isEmpty() ? NoActiveSheetsChanged 62 return changedRuleSets.isEmpty() ? NoActiveSheetsChanged
63 : ActiveSheetsChanged; 63 : ActiveSheetsChanged;
64 } 64 }
65 65
66 DCHECK(index < oldStyleSheetCount && index < newStyleSheetCount); 66 DCHECK(index < oldStyleSheetCount && index < newStyleSheetCount);
67 67
68 // Both the new and old active stylesheet vectors have stylesheets following 68 // Both the new and old active stylesheet vectors have stylesheets following
69 // the common prefix. Figure out which were added or removed by sorting the 69 // the common prefix. Figure out which were added or removed by sorting the
70 // merged vector of old and new sheets. 70 // merged vector of old and new sheets.
71 71
72 ActiveStyleSheetVector mergedSorted; 72 ActiveStyleSheetVector mergedSorted;
73 mergedSorted.reserveCapacity(oldStyleSheetCount + newStyleSheetCount - 73 mergedSorted.reserveCapacity(oldStyleSheetCount + newStyleSheetCount -
74 2 * index); 74 2 * index);
75 mergedSorted.appendRange(oldStyleSheets.begin() + index, 75 mergedSorted.appendRange(oldStyleSheets.begin() + index,
76 oldStyleSheets.end()); 76 oldStyleSheets.end());
77 mergedSorted.appendRange(newStyleSheets.begin() + index, 77 mergedSorted.appendRange(newStyleSheets.begin() + index,
78 newStyleSheets.end()); 78 newStyleSheets.end());
79 79
80 std::sort(mergedSorted.begin(), mergedSorted.end()); 80 std::sort(mergedSorted.begin(), mergedSorted.end());
81 81
82 auto mergedIterator = mergedSorted.begin(); 82 auto mergedIterator = mergedSorted.begin();
83 while (mergedIterator != mergedSorted.end()) { 83 while (mergedIterator != mergedSorted.end()) {
84 const auto& sheet1 = *mergedIterator++; 84 const auto& sheet1 = *mergedIterator++;
85 if (mergedIterator == mergedSorted.end() || 85 if (mergedIterator == mergedSorted.end() ||
86 (*mergedIterator).first != sheet1.first) { 86 (*mergedIterator).first != sheet1.first) {
87 // Sheet either removed or inserted. 87 // Sheet either removed or inserted.
88 if (sheet1.second) 88 if (sheet1.second)
89 changedRuleSets.add(sheet1.second); 89 changedRuleSets.insert(sheet1.second);
90 continue; 90 continue;
91 } 91 }
92 92
93 // Sheet present in both old and new. 93 // Sheet present in both old and new.
94 const auto& sheet2 = *mergedIterator++; 94 const auto& sheet2 = *mergedIterator++;
95 95
96 if (sheet1.second == sheet2.second) 96 if (sheet1.second == sheet2.second)
97 continue; 97 continue;
98 98
99 // Active rules for the given stylesheet changed. 99 // Active rules for the given stylesheet changed.
100 // DOM, CSSOM, or media query changes. 100 // DOM, CSSOM, or media query changes.
101 if (sheet1.second) 101 if (sheet1.second)
102 changedRuleSets.add(sheet1.second); 102 changedRuleSets.insert(sheet1.second);
103 if (sheet2.second) 103 if (sheet2.second)
104 changedRuleSets.add(sheet2.second); 104 changedRuleSets.insert(sheet2.second);
105 } 105 }
106 return changedRuleSets.isEmpty() ? NoActiveSheetsChanged 106 return changedRuleSets.isEmpty() ? NoActiveSheetsChanged
107 : ActiveSheetsChanged; 107 : ActiveSheetsChanged;
108 } 108 }
109 109
110 } // namespace blink 110 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698