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

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

Issue 2755493004: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/css/ (Closed)
Patch Set: All windows error are Resolved now. Created 3 years, 8 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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 56
57 CSSSelectorList CSSSelectorList::adoptSelectorVector( 57 CSSSelectorList CSSSelectorList::adoptSelectorVector(
58 Vector<std::unique_ptr<CSSParserSelector>>& selectorVector) { 58 Vector<std::unique_ptr<CSSParserSelector>>& selectorVector) {
59 size_t flattenedSize = 0; 59 size_t flattenedSize = 0;
60 for (size_t i = 0; i < selectorVector.size(); ++i) { 60 for (size_t i = 0; i < selectorVector.size(); ++i) {
61 for (CSSParserSelector* selector = selectorVector[i].get(); selector; 61 for (CSSParserSelector* selector = selectorVector[i].get(); selector;
62 selector = selector->tagHistory()) 62 selector = selector->tagHistory())
63 ++flattenedSize; 63 ++flattenedSize;
64 } 64 }
65 ASSERT(flattenedSize); 65 DCHECK(flattenedSize);
66 66
67 CSSSelectorList list; 67 CSSSelectorList list;
68 list.m_selectorArray = 68 list.m_selectorArray =
69 reinterpret_cast<CSSSelector*>(WTF::Partitions::fastMalloc( 69 reinterpret_cast<CSSSelector*>(WTF::Partitions::fastMalloc(
70 sizeof(CSSSelector) * flattenedSize, kCSSSelectorTypeName)); 70 sizeof(CSSSelector) * flattenedSize, kCSSSelectorTypeName));
71 size_t arrayIndex = 0; 71 size_t arrayIndex = 0;
72 for (size_t i = 0; i < selectorVector.size(); ++i) { 72 for (size_t i = 0; i < selectorVector.size(); ++i) {
73 CSSParserSelector* current = selectorVector[i].get(); 73 CSSParserSelector* current = selectorVector[i].get();
74 while (current) { 74 while (current) {
75 // Move item from the parser selector vector into m_selectorArray without 75 // Move item from the parser selector vector into m_selectorArray without
76 // invoking destructor (Ugh.) 76 // invoking destructor (Ugh.)
77 CSSSelector* currentSelector = current->releaseSelector().release(); 77 CSSSelector* currentSelector = current->releaseSelector().release();
78 memcpy(&list.m_selectorArray[arrayIndex], currentSelector, 78 memcpy(&list.m_selectorArray[arrayIndex], currentSelector,
79 sizeof(CSSSelector)); 79 sizeof(CSSSelector));
80 WTF::Partitions::fastFree(currentSelector); 80 WTF::Partitions::fastFree(currentSelector);
81 81
82 current = current->tagHistory(); 82 current = current->tagHistory();
83 ASSERT(!list.m_selectorArray[arrayIndex].isLastInSelectorList()); 83 DCHECK(!list.m_selectorArray[arrayIndex].isLastInSelectorList());
84 if (current) 84 if (current)
85 list.m_selectorArray[arrayIndex].setNotLastInTagHistory(); 85 list.m_selectorArray[arrayIndex].setNotLastInTagHistory();
86 ++arrayIndex; 86 ++arrayIndex;
87 } 87 }
88 ASSERT(list.m_selectorArray[arrayIndex - 1].isLastInTagHistory()); 88 DCHECK(list.m_selectorArray[arrayIndex - 1].isLastInTagHistory());
89 } 89 }
90 ASSERT(flattenedSize == arrayIndex); 90 DCHECK_EQ(flattenedSize, arrayIndex);
91 list.m_selectorArray[arrayIndex - 1].setLastInSelectorList(); 91 list.m_selectorArray[arrayIndex - 1].setLastInSelectorList();
92 selectorVector.clear(); 92 selectorVector.clear();
93 93
94 return list; 94 return list;
95 } 95 }
96 96
97 unsigned CSSSelectorList::computeLength() const { 97 unsigned CSSSelectorList::computeLength() const {
98 if (!m_selectorArray) 98 if (!m_selectorArray)
99 return 0; 99 return 0;
100 CSSSelector* current = m_selectorArray; 100 CSSSelector* current = m_selectorArray;
101 while (!current->isLastInSelectorList()) 101 while (!current->isLastInSelectorList())
102 ++current; 102 ++current;
103 return (current - m_selectorArray) + 1; 103 return (current - m_selectorArray) + 1;
104 } 104 }
105 105
106 void CSSSelectorList::deleteSelectors() { 106 void CSSSelectorList::deleteSelectors() {
107 ASSERT(m_selectorArray); 107 DCHECK(m_selectorArray);
108 108
109 bool finished = false; 109 bool finished = false;
110 for (CSSSelector* s = m_selectorArray; !finished; ++s) { 110 for (CSSSelector* s = m_selectorArray; !finished; ++s) {
111 finished = s->isLastInSelectorList(); 111 finished = s->isLastInSelectorList();
112 s->~CSSSelector(); 112 s->~CSSSelector();
113 } 113 }
114 114
115 WTF::Partitions::fastFree(m_selectorArray); 115 WTF::Partitions::fastFree(m_selectorArray);
116 } 116 }
117 117
118 String CSSSelectorList::selectorsText() const { 118 String CSSSelectorList::selectorsText() const {
119 StringBuilder result; 119 StringBuilder result;
120 120
121 for (const CSSSelector* s = first(); s; s = next(*s)) { 121 for (const CSSSelector* s = first(); s; s = next(*s)) {
122 if (s != first()) 122 if (s != first())
123 result.append(", "); 123 result.append(", ");
124 result.append(s->selectorText()); 124 result.append(s->selectorText());
125 } 125 }
126 126
127 return result.toString(); 127 return result.toString();
128 } 128 }
129 129
130 } // namespace blink 130 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSelector.cpp ('k') | third_party/WebKit/Source/core/css/CSSStyleRule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698