Modified: trunk/Source/WebCore/css/CSSParser.cpp (110304 => 110305)
--- trunk/Source/WebCore/css/CSSParser.cpp 2012-03-09 18:02:46 UTC (rev 110304)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2012-03-09 19:05:40 UTC (rev 110305)
@@ -178,17 +178,11 @@
m_cssValuePool = CSSValuePool::create();
}
-// FIXME: Can m_parsedProperties just be a Vector?
-
CSSParser::CSSParser(bool strictParsing)
: m_strict(strictParsing)
, m_important(false)
, m_id(0)
, m_styleSheet(0)
- , m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*))))
- , m_numParsedProperties(0)
- , m_maxParsedProperties(32)
- , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
, m_inParseShorthand(0)
, m_currentShorthand(0)
, m_implicitShorthand(false)
@@ -218,7 +212,6 @@
CSSParser::~CSSParser()
{
clearProperties();
- fastFree(m_parsedProperties);
fastDeleteAllValues(m_floatingSelectors);
deleteAllValues(m_floatingSelectorVectors);
@@ -520,9 +513,9 @@
bool ok = false;
if (m_hasFontFaceOnlyValues)
deleteFontFaceOnlyValues();
- if (m_numParsedProperties) {
+ if (!m_parsedProperties.isEmpty()) {
ok = true;
- declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
+ declaration->addParsedProperties(m_parsedProperties.data(), m_parsedProperties.size());
clearProperties();
}
@@ -543,7 +536,7 @@
if (!parser.parseColor(string))
return false;
- CSSValue* value = parser.m_parsedProperties[0]->value();
+ CSSValue* value = parser.m_parsedProperties.first().value();
if (!value->isPrimitiveValue())
return false;
@@ -565,7 +558,7 @@
cssyyparse(this);
m_rule = 0;
- return (m_numParsedProperties && m_parsedProperties[0]->m_id == CSSPropertyColor);
+ return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
}
bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
@@ -621,9 +614,9 @@
bool ok = false;
if (m_hasFontFaceOnlyValues)
deleteFontFaceOnlyValues();
- if (m_numParsedProperties) {
+ if (!m_parsedProperties.isEmpty()) {
ok = true;
- declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties);
+ declaration->addParsedProperties(m_parsedProperties.data(), m_parsedProperties.size());
clearProperties();
}
@@ -667,31 +660,19 @@
void CSSParser::addProperty(int propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
{
- OwnPtr<CSSProperty> prop(adoptPtr(new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand || implicit)));
- if (m_numParsedProperties >= m_maxParsedProperties) {
- if (m_numParsedProperties > (UINT_MAX / sizeof(CSSProperty*)) - 32)
- CRASH(); // Avoid inconsistencies with rollbackLastProperties.
- m_maxParsedProperties += 32;
- m_parsedProperties = static_cast<CSSProperty**>(fastRealloc(m_parsedProperties,
- m_maxParsedProperties * sizeof(CSSProperty*)));
- }
- m_parsedProperties[m_numParsedProperties++] = prop.leakPtr();
+ m_parsedProperties.append(CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand || implicit));
}
void CSSParser::rollbackLastProperties(int num)
{
ASSERT(num >= 0);
- ASSERT(m_numParsedProperties >= static_cast<unsigned>(num));
-
- for (int i = 0; i < num; ++i)
- delete m_parsedProperties[--m_numParsedProperties];
+ ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
+ m_parsedProperties.shrink(m_parsedProperties.size() - num);
}
void CSSParser::clearProperties()
{
- for (unsigned i = 0; i < m_numParsedProperties; i++)
- delete m_parsedProperties[i];
- m_numParsedProperties = 0;
+ m_parsedProperties.clear();
m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
m_hasFontFaceOnlyValues = false;
}
@@ -1072,7 +1053,7 @@
ShorthandScope scope(this, propId);
if (num != 1 || !parseValue(CSSPropertyOverflowX, important))
return false;
- CSSValue* value = m_parsedProperties[m_numParsedProperties - 1]->value();
+ CSSValue* value = m_parsedProperties.last().value();
addProperty(CSSPropertyOverflowY, value, important);
return true;
}
@@ -1166,7 +1147,7 @@
ShorthandScope scope(this, CSSPropertyBorderSpacing);
if (!parseValue(properties[0], important))
return false;
- CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
+ CSSValue* value = m_parsedProperties.last().value();
addProperty(properties[1], value, important);
return true;
}
@@ -1913,7 +1894,7 @@
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
if (!parseValue(properties[0], important))
return false;
- CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value();
+ CSSValue* value = m_parsedProperties.last().value();
addProperty(properties[1], value, important);
return true;
}
@@ -2754,7 +2735,7 @@
case 1: {
if (!parseValue(properties[0], important))
return false;
- CSSValue *value = m_parsedProperties[m_numParsedProperties-1]->value();
+ CSSValue *value = m_parsedProperties.last().value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[1], value, important);
addProperty(properties[2], value, important);
@@ -2764,17 +2745,17 @@
case 2: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
- CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
+ CSSValue *value = m_parsedProperties[m_parsedProperties.size() - 2].value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[2], value, important);
- value = m_parsedProperties[m_numParsedProperties-2]->value();
+ value = m_parsedProperties[m_parsedProperties.size() - 2].value();
addProperty(properties[3], value, important);
break;
}
case 3: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
return false;
- CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value();
+ CSSValue *value = m_parsedProperties[m_parsedProperties.size() - 2].value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[3], value, important);
break;
@@ -7119,7 +7100,7 @@
m_rule = 0;
- return ((m_numParsedProperties == 1) && (m_parsedProperties[0]->m_id == CSSPropertyWebkitFlowInto));
+ return ((m_parsedProperties.size() == 1) && (m_parsedProperties.first().id() == CSSPropertyWebkitFlowInto));
}
// none | <ident>
@@ -8864,7 +8845,7 @@
rule->styleRule()->adoptSelectorVector(*selectors);
if (m_hasFontFaceOnlyValues)
deleteFontFaceOnlyValues();
- rule->styleRule()->setProperties(StylePropertySet::create(m_parsedProperties, m_numParsedProperties, m_strict));
+ rule->styleRule()->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_strict));
result = rule.get();
m_parsedRules.append(rule.release());
if (m_ruleRangeMap) {
@@ -8886,14 +8867,13 @@
CSSRule* CSSParser::createFontFaceRule()
{
m_allowImportRules = m_allowNamespaceDeclarations = false;
- for (unsigned i = 0; i < m_numParsedProperties; ++i) {
- CSSProperty* property = m_parsedProperties[i];
- int id = property->id();
- if (id == CSSPropertyFontVariant && property->value()->isPrimitiveValue()) {
- RefPtr<CSSValue> value = property->m_value.release();
- property->m_value = CSSValueList::createCommaSeparated();
- static_cast<CSSValueList*>(property->value())->append(value.release());
- } else if (id == CSSPropertyFontFamily && (!property->value()->isValueList() || static_cast<CSSValueList*>(property->value())->length() != 1)) {
+ for (unsigned i = 0; i < m_parsedProperties.size(); ++i) {
+ CSSProperty& property = m_parsedProperties[i];
+ if (property.id() == CSSPropertyFontVariant && property.value()->isPrimitiveValue()) {
+ RefPtr<CSSValue> value = property.m_value.release();
+ property.m_value = CSSValueList::createCommaSeparated();
+ static_cast<CSSValueList*>(property.value())->append(value.release());
+ } else if (property.id() == CSSPropertyFontFamily && (!property.value()->isValueList() || static_cast<CSSValueList*>(property.value())->length() != 1)) {
// Unlike font-family property, font-family descriptor in @font-face rule
// has to be a value list with exactly one family name. It cannot have a
// have 'initial' value and cannot 'inherit' from parent.
@@ -8903,7 +8883,7 @@
}
}
RefPtr<CSSFontFaceRule> rule = CSSFontFaceRule::create(m_styleSheet);
- rule->setDeclaration(StylePropertySet::create(m_parsedProperties, m_numParsedProperties, m_strict));
+ rule->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_strict));
clearProperties();
CSSFontFaceRule* result = rule.get();
m_parsedRules.append(rule.release());
@@ -8974,7 +8954,7 @@
Vector<OwnPtr<CSSParserSelector> > selectorVector;
selectorVector.append(pageSelector);
rule->adoptSelectorVector(selectorVector);
- rule->setDeclaration(StylePropertySet::create(m_parsedProperties, m_numParsedProperties, m_strict));
+ rule->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_strict));
pageRule = rule.get();
m_parsedRules.append(rule.release());
}
@@ -9007,7 +8987,7 @@
{
// FIXME: Implement margin at-rule here, using:
// - marginBox: margin box
- // - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMarginBox, m_numParsedProperties) are for this at-rule.
+ // - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMarginBox, m_parsedProperties.size()] are for this at-rule.
// Don't forget to also update the action for page symbol in CSSGrammar.y such that margin at-rule data is cleared if page_selector is invalid.
endDeclarationsForMarginBox();
@@ -9016,32 +8996,26 @@
void CSSParser::startDeclarationsForMarginBox()
{
- m_numParsedPropertiesBeforeMarginBox = m_numParsedProperties;
+ m_numParsedPropertiesBeforeMarginBox = m_parsedProperties.size();
}
void CSSParser::endDeclarationsForMarginBox()
{
- ASSERT(m_numParsedPropertiesBeforeMarginBox != INVALID_NUM_PARSED_PROPERTIES);
- rollbackLastProperties(m_numParsedProperties - m_numParsedPropertiesBeforeMarginBox);
+ rollbackLastProperties(m_parsedProperties.size() - m_numParsedPropertiesBeforeMarginBox);
m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
}
void CSSParser::deleteFontFaceOnlyValues()
{
ASSERT(m_hasFontFaceOnlyValues);
- int deletedProperties = 0;
-
- for (unsigned i = 0; i < m_numParsedProperties; ++i) {
- CSSProperty* property = m_parsedProperties[i];
- int id = property->id();
- if (id == CSSPropertyFontVariant && property->value()->isValueList()) {
- delete property;
- deletedProperties++;
- } else if (deletedProperties)
- m_parsedProperties[i - deletedProperties] = m_parsedProperties[i];
+ for (unsigned i = 0; i < m_parsedProperties.size();) {
+ CSSProperty& property = m_parsedProperties[i];
+ if (property.id() == CSSPropertyFontVariant && property.value()->isValueList()) {
+ m_parsedProperties.remove(i);
+ continue;
+ }
+ ++i;
}
-
- m_numParsedProperties -= deletedProperties;
}
WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(CSSParserValueList* keys)
@@ -9058,7 +9032,7 @@
RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet);
keyframe->setKeyText(keyString);
- keyframe->setDeclaration(StylePropertySet::create(m_parsedProperties, m_numParsedProperties, m_strict));
+ keyframe->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_strict));
clearProperties();
Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (110304 => 110305)
--- trunk/Source/WebCore/css/StylePropertySet.cpp 2012-03-09 18:02:46 UTC (rev 110304)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp 2012-03-09 19:05:40 UTC (rev 110305)
@@ -57,26 +57,27 @@
m_properties.shrinkToFit();
}
-StylePropertySet::StylePropertySet(const CSSProperty* const * properties, int numProperties, bool useStrictParsing)
+StylePropertySet::StylePropertySet(const CSSProperty* properties, int numProperties, bool useStrictParsing)
: m_strictParsing(useStrictParsing)
, m_hasCSSOMWrapper(false)
{
+ // FIXME: This logic belongs in CSSParser.
+
m_properties.reserveInitialCapacity(numProperties);
HashMap<int, bool> candidates;
for (int i = 0; i < numProperties; ++i) {
- const CSSProperty *property = properties[i];
- ASSERT(property);
- bool important = property->isImportant();
+ const CSSProperty& property = properties[i];
+ bool important = property.isImportant();
- HashMap<int, bool>::iterator it = candidates.find(property->id());
+ HashMap<int, bool>::iterator it = candidates.find(property.id());
if (it != candidates.end()) {
if (!important && it->second)
continue;
- removeProperty(property->id());
+ removeProperty(property.id());
}
- m_properties.append(*property);
- candidates.set(property->id(), important);
+ m_properties.append(property);
+ candidates.set(property.id(), important);
}
}
@@ -628,11 +629,11 @@
parser.parseDeclaration(this, styleDeclaration, 0, contextStyleSheet);
}
-void StylePropertySet::addParsedProperties(const CSSProperty* const* properties, int numProperties)
+void StylePropertySet::addParsedProperties(const CSSProperty* properties, int numProperties)
{
m_properties.reserveCapacity(numProperties);
for (int i = 0; i < numProperties; ++i)
- addParsedProperty(*properties[i]);
+ addParsedProperty(properties[i]);
}
void StylePropertySet::addParsedProperty(const CSSProperty& property)
Modified: trunk/Source/WebCore/css/StylePropertySet.h (110304 => 110305)
--- trunk/Source/WebCore/css/StylePropertySet.h 2012-03-09 18:02:46 UTC (rev 110304)
+++ trunk/Source/WebCore/css/StylePropertySet.h 2012-03-09 19:05:40 UTC (rev 110305)
@@ -43,7 +43,7 @@
{
return adoptRef(new StylePropertySet);
}
- static PassRefPtr<StylePropertySet> create(const CSSProperty* const* properties, int numProperties, bool useStrictParsing)
+ static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, int numProperties, bool useStrictParsing)
{
return adoptRef(new StylePropertySet(properties, numProperties, useStrictParsing));
}
@@ -76,7 +76,7 @@
void parseDeclaration(const String& styleDeclaration, CSSStyleSheet* contextStyleSheet);
- void addParsedProperties(const CSSProperty* const *, int numProperties);
+ void addParsedProperties(const CSSProperty*, int numProperties);
void addParsedProperty(const CSSProperty&);
PassRefPtr<StylePropertySet> copyBlockProperties() const;
@@ -113,7 +113,7 @@
private:
StylePropertySet();
StylePropertySet(const Vector<CSSProperty>&);
- StylePropertySet(const CSSProperty* const *, int numProperties, bool useStrictParsing);
+ StylePropertySet(const CSSProperty*, int numProperties, bool useStrictParsing);
void setNeedsStyleRecalc();