OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "core/css/CSSSelectorList.h" | 27 #include "core/css/CSSSelectorList.h" |
28 | 28 |
29 #include "core/css/parser/CSSParserSelector.h" | 29 #include "core/css/parser/CSSParserSelector.h" |
30 #include "wtf/Partitions.h" | 30 #include "wtf/Partitions.h" |
31 #include "wtf/text/StringBuilder.h" | 31 #include "wtf/text/StringBuilder.h" |
32 | 32 |
| 33 namespace { |
| 34 // CSSSelector is one of the top types that consume renderer memory, |
| 35 // so instead of using the |WTF_HEAP_PROFILER_TYPE_NAME| macro in the |
| 36 // allocations below, pass this type name constant to allow profiling |
| 37 // in official builds. |
| 38 const char kCSSSelectorTypeName[] = "blink::CSSSelector"; |
| 39 } |
| 40 |
33 namespace blink { | 41 namespace blink { |
34 | 42 |
35 CSSSelectorList CSSSelectorList::copy() const | 43 CSSSelectorList CSSSelectorList::copy() const |
36 { | 44 { |
37 CSSSelectorList list; | 45 CSSSelectorList list; |
38 | 46 |
39 unsigned length = this->length(); | 47 unsigned length = this->length(); |
40 list.m_selectorArray = reinterpret_cast<CSSSelector*>(WTF::Partitions::fastM
alloc(sizeof(CSSSelector) * length, WTF_HEAP_PROFILER_TYPE_NAME(CSSSelector))); | 48 list.m_selectorArray = reinterpret_cast<CSSSelector*>(WTF::Partitions::fastM
alloc(sizeof(CSSSelector) * length, kCSSSelectorTypeName)); |
41 for (unsigned i = 0; i < length; ++i) | 49 for (unsigned i = 0; i < length; ++i) |
42 new (&list.m_selectorArray[i]) CSSSelector(m_selectorArray[i]); | 50 new (&list.m_selectorArray[i]) CSSSelector(m_selectorArray[i]); |
43 | 51 |
44 return list; | 52 return list; |
45 } | 53 } |
46 | 54 |
47 CSSSelectorList CSSSelectorList::adoptSelectorVector(Vector<OwnPtr<CSSParserSele
ctor>>& selectorVector) | 55 CSSSelectorList CSSSelectorList::adoptSelectorVector(Vector<OwnPtr<CSSParserSele
ctor>>& selectorVector) |
48 { | 56 { |
49 size_t flattenedSize = 0; | 57 size_t flattenedSize = 0; |
50 for (size_t i = 0; i < selectorVector.size(); ++i) { | 58 for (size_t i = 0; i < selectorVector.size(); ++i) { |
51 for (CSSParserSelector* selector = selectorVector[i].get(); selector; se
lector = selector->tagHistory()) | 59 for (CSSParserSelector* selector = selectorVector[i].get(); selector; se
lector = selector->tagHistory()) |
52 ++flattenedSize; | 60 ++flattenedSize; |
53 } | 61 } |
54 ASSERT(flattenedSize); | 62 ASSERT(flattenedSize); |
55 | 63 |
56 CSSSelectorList list; | 64 CSSSelectorList list; |
57 list.m_selectorArray = reinterpret_cast<CSSSelector*>(WTF::Partitions::fastM
alloc(sizeof(CSSSelector) * flattenedSize, WTF_HEAP_PROFILER_TYPE_NAME(CSSSelect
or))); | 65 list.m_selectorArray = reinterpret_cast<CSSSelector*>(WTF::Partitions::fastM
alloc(sizeof(CSSSelector) * flattenedSize, kCSSSelectorTypeName)); |
58 size_t arrayIndex = 0; | 66 size_t arrayIndex = 0; |
59 for (size_t i = 0; i < selectorVector.size(); ++i) { | 67 for (size_t i = 0; i < selectorVector.size(); ++i) { |
60 CSSParserSelector* current = selectorVector[i].get(); | 68 CSSParserSelector* current = selectorVector[i].get(); |
61 while (current) { | 69 while (current) { |
62 // Move item from the parser selector vector into m_selectorArray wi
thout invoking destructor (Ugh.) | 70 // Move item from the parser selector vector into m_selectorArray wi
thout invoking destructor (Ugh.) |
63 CSSSelector* currentSelector = current->releaseSelector().leakPtr(); | 71 CSSSelector* currentSelector = current->releaseSelector().leakPtr(); |
64 memcpy(&list.m_selectorArray[arrayIndex], currentSelector, sizeof(CS
SSelector)); | 72 memcpy(&list.m_selectorArray[arrayIndex], currentSelector, sizeof(CS
SSelector)); |
65 WTF::Partitions::fastFree(currentSelector); | 73 WTF::Partitions::fastFree(currentSelector); |
66 | 74 |
67 current = current->tagHistory(); | 75 current = current->tagHistory(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 176 } |
169 | 177 |
170 bool CSSSelectorList::selectorNeedsUpdatedDistribution(size_t index) const | 178 bool CSSSelectorList::selectorNeedsUpdatedDistribution(size_t index) const |
171 { | 179 { |
172 return forEachTagSelector([](const CSSSelector& selector) -> bool { | 180 return forEachTagSelector([](const CSSSelector& selector) -> bool { |
173 return selector.relationIsAffectedByPseudoContent() || selector.pseudoTy
pe() == CSSSelector::PseudoHostContext; | 181 return selector.relationIsAffectedByPseudoContent() || selector.pseudoTy
pe() == CSSSelector::PseudoHostContext; |
174 }, selectorAt(index)); | 182 }, selectorAt(index)); |
175 } | 183 } |
176 | 184 |
177 } // namespace blink | 185 } // namespace blink |
OLD | NEW |