Modified: trunk/Source/WebCore/WebCore.exp.in (129542 => 129543)
--- trunk/Source/WebCore/WebCore.exp.in 2012-09-25 19:30:56 UTC (rev 129542)
+++ trunk/Source/WebCore/WebCore.exp.in 2012-09-25 19:55:15 UTC (rev 129543)
@@ -614,6 +614,7 @@
__ZN7WebCore25HistoryPropertyListWriter16writeHistoryItemERNS_30BinaryPropertyListObjectStreamEPNS_11HistoryItemE
__ZN7WebCore25HistoryPropertyListWriter6bufferEm
__ZN7WebCore25HistoryPropertyListWriterC2Ev
+__ZN7WebCore25ImmutableStylePropertySetD1Ev
__ZN7WebCore25addLanguageChangeObserverEPvPFvS0_E
__ZN7WebCore25computeViewportAttributesENS_17ViewportArgumentsEiiifNS_7IntSizeE
__ZN7WebCore26UserTypingGestureIndicator27processingUserTypingGestureEv
@@ -829,6 +830,7 @@
__ZN7WebCore7jsArrayEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEN3WTF10PassRefPtrINS_13DOMStringListEEE
__ZN7WebCore7replaceERN3WTF6StringERKNS_17RegularExpressionERKS1_
__ZN7WebCore7toRangeEN3JSC7JSValueE
+__ZN7WebCore8CSSValue7destroyEv
__ZN7WebCore8Document11createRangeEv
__ZN7WebCore8Document12updateLayoutEv
__ZN7WebCore8Document14setFocusedNodeEN3WTF10PassRefPtrINS_4NodeEEE
@@ -1554,6 +1556,7 @@
__ZN7WebCore16colorFromNSColorEP7NSColor
__ZN7WebCore16enclosingIntRectERK7_NSRect
__ZN7WebCore16StylePropertySet25ensureCSSStyleDeclarationEv
+__ZN7WebCore16StylePropertySetD2Ev
__ZN7WebCore21DeviceOrientationData6createEbdbdbdbb
__ZN7WebCore18SearchPopupMenuMacC1EPNS_15PopupMenuClientE
__ZN7WebCore19applicationIsSafariEv
Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (129542 => 129543)
--- trunk/Source/WebCore/css/StylePropertySet.cpp 2012-09-25 19:30:56 UTC (rev 129542)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp 2012-09-25 19:55:15 UTC (rev 129543)
@@ -53,77 +53,60 @@
static size_t immutableStylePropertySetSize(unsigned count)
{
- return sizeof(StylePropertySet) - sizeof(void*) + sizeof(CSSProperty) * count;
+ return sizeof(ImmutableStylePropertySet) + sizeof(CSSProperty) * count;
}
PassRefPtr<StylePropertySet> StylePropertySet::createImmutable(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
{
void* slot = WTF::fastMalloc(immutableStylePropertySetSize(count));
- return adoptRef(new (slot) StylePropertySet(properties, count, cssParserMode, /* makeMutable */ false));
+ return adoptRef(new (slot) ImmutableStylePropertySet(properties, count, cssParserMode));
}
PassRefPtr<StylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
{
if (!isMutable())
return const_cast<StylePropertySet*>(this);
- return createImmutable(m_mutablePropertyVector->data(), m_mutablePropertyVector->size(), cssParserMode());
+ return createImmutable(mutablePropertyVector().data(), mutablePropertyVector().size(), cssParserMode());
}
-StylePropertySet::StylePropertySet(CSSParserMode cssParserMode)
- : m_cssParserMode(cssParserMode)
- , m_ownsCSSOMWrapper(false)
- , m_isMutable(true)
- , m_arraySize(0)
- , m_mutablePropertyVector(new Vector<CSSProperty>)
+MutableStylePropertySet::MutableStylePropertySet(const CSSProperty* properties, unsigned length)
+ : StylePropertySet(CSSStrictMode)
{
+ m_propertyVector.reserveInitialCapacity(length);
+ for (unsigned i = 0; i < length; ++i)
+ m_propertyVector.uncheckedAppend(properties[i]);
}
-StylePropertySet::StylePropertySet(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode, bool makeMutable)
- : m_cssParserMode(cssParserMode)
- , m_ownsCSSOMWrapper(false)
- , m_isMutable(makeMutable)
+ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properties, unsigned length, CSSParserMode cssParserMode)
+ : StylePropertySet(cssParserMode, length)
{
- if (makeMutable) {
- m_mutablePropertyVector = new Vector<CSSProperty>;
- m_mutablePropertyVector->reserveInitialCapacity(count);
- for (unsigned i = 0; i < count; ++i)
- m_mutablePropertyVector->uncheckedAppend(properties[i]);
- } else {
- m_arraySize = count;
- for (unsigned i = 0; i < m_arraySize; ++i)
- new (&array()[i]) CSSProperty(properties[i]);
- }
+ for (unsigned i = 0; i < length; ++i)
+ new (&reinterpret_cast<CSSProperty*>(&m_propertyArray)[i]) CSSProperty(properties[i]);
}
-StylePropertySet::StylePropertySet(const StylePropertySet& other)
- : RefCounted<StylePropertySet>()
- , m_cssParserMode(other.m_cssParserMode)
- , m_ownsCSSOMWrapper(false)
- , m_isMutable(true)
- , m_arraySize(0)
- , m_mutablePropertyVector(new Vector<CSSProperty>)
+MutableStylePropertySet::MutableStylePropertySet(const StylePropertySet& other)
+ : StylePropertySet(other.cssParserMode())
{
if (other.isMutable())
- *m_mutablePropertyVector = *other.m_mutablePropertyVector;
+ m_propertyVector = static_cast<const MutableStylePropertySet&>(other).mutablePropertyVector();
else {
- m_mutablePropertyVector->clear();
- m_mutablePropertyVector->reserveCapacity(other.m_arraySize);
- for (unsigned i = 0; i < other.m_arraySize; ++i)
- m_mutablePropertyVector->uncheckedAppend(other.array()[i]);
+ m_propertyVector.reserveInitialCapacity(other.propertyCount());
+ for (unsigned i = 0; i < other.propertyCount(); ++i)
+ m_propertyVector.uncheckedAppend(other.immutablePropertyArray()[i]);
}
}
+ImmutableStylePropertySet::~ImmutableStylePropertySet()
+{
+ for (unsigned i = 0; i < m_arraySize; ++i)
+ immutablePropertyArray()[i].~CSSProperty();
+}
+
StylePropertySet::~StylePropertySet()
{
ASSERT(!m_ownsCSSOMWrapper || propertySetCSSOMWrapperMap().contains(this));
if (m_ownsCSSOMWrapper)
propertySetCSSOMWrapperMap().remove(this);
- if (isMutable())
- delete m_mutablePropertyVector;
- else {
- for (unsigned i = 0; i < m_arraySize; ++i)
- array()[i].~CSSProperty();
- }
}
String StylePropertySet::getPropertyValue(CSSPropertyID propertyID) const
@@ -532,7 +515,7 @@
// A more efficient removal strategy would involve marking entries as empty
// and sweeping them when the vector grows too big.
- m_mutablePropertyVector->remove(foundProperty - m_mutablePropertyVector->data());
+ mutablePropertyVector().remove(foundProperty - mutablePropertyVector().data());
return true;
}
@@ -621,7 +604,7 @@
{
ASSERT(isMutable());
- m_mutablePropertyVector->clear();
+ mutablePropertyVector().clear();
CSSParserContext context(cssParserMode());
if (contextStyleSheet) {
@@ -635,7 +618,7 @@
void StylePropertySet::addParsedProperties(const Vector<CSSProperty>& properties)
{
ASSERT(isMutable());
- m_mutablePropertyVector->reserveCapacity(m_mutablePropertyVector->size() + properties.size());
+ mutablePropertyVector().reserveCapacity(mutablePropertyVector().size() + properties.size());
for (unsigned i = 0; i < properties.size(); ++i)
addParsedProperty(properties[i]);
}
@@ -975,7 +958,7 @@
bool StylePropertySet::removePropertiesInSet(const CSSPropertyID* set, unsigned length)
{
ASSERT(isMutable());
- if (m_mutablePropertyVector->isEmpty())
+ if (mutablePropertyVector().isEmpty())
return false;
// FIXME: This is always used with static sets and in that case constructing the hash repeatedly is pretty pointless.
@@ -984,11 +967,11 @@
toRemove.add(set[i]);
Vector<CSSProperty> newProperties;
- newProperties.reserveInitialCapacity(m_mutablePropertyVector->size());
+ newProperties.reserveInitialCapacity(mutablePropertyVector().size());
- unsigned size = m_mutablePropertyVector->size();
+ unsigned size = mutablePropertyVector().size();
for (unsigned n = 0; n < size; ++n) {
- const CSSProperty& property = m_mutablePropertyVector->at(n);
+ const CSSProperty& property = mutablePropertyVector().at(n);
// Not quite sure if the isImportant test is needed but it matches the existing behavior.
if (!property.isImportant()) {
if (toRemove.contains(property.id()))
@@ -997,8 +980,8 @@
newProperties.append(property);
}
- bool changed = newProperties.size() != m_mutablePropertyVector->size();
- *m_mutablePropertyVector = newProperties;
+ bool changed = newProperties.size() != mutablePropertyVector().size();
+ mutablePropertyVector() = newProperties;
return changed;
}
@@ -1031,9 +1014,9 @@
{
ASSERT(isMutable());
Vector<CSSPropertyID> propertiesToRemove;
- unsigned size = m_mutablePropertyVector->size();
+ unsigned size = mutablePropertyVector().size();
for (unsigned i = 0; i < size; ++i) {
- const CSSProperty& property = m_mutablePropertyVector->at(i);
+ const CSSProperty& property = mutablePropertyVector().at(i);
if (style->propertyMatches(&property))
propertiesToRemove.append(property.id());
}
@@ -1046,9 +1029,9 @@
{
ASSERT(isMutable());
Vector<CSSPropertyID> propertiesToRemove;
- unsigned size = m_mutablePropertyVector->size();
+ unsigned size = mutablePropertyVector().size();
for (unsigned i = 0; i < size; ++i) {
- const CSSProperty& property = m_mutablePropertyVector->at(i);
+ const CSSProperty& property = mutablePropertyVector().at(i);
if (style->cssPropertyMatches(&property))
propertiesToRemove.append(property.id());
}
@@ -1059,7 +1042,7 @@
PassRefPtr<StylePropertySet> StylePropertySet::copy() const
{
- return adoptRef(new StylePropertySet(*this));
+ return adoptRef(new MutableStylePropertySet(*this));
}
PassRefPtr<StylePropertySet> StylePropertySet::copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const
@@ -1122,7 +1105,7 @@
size_t actualSize = m_isMutable ? sizeof(StylePropertySet) : immutableStylePropertySetSize(m_arraySize);
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS, actualSize);
if (m_isMutable)
- info.addMember(m_mutablePropertyVector);
+ info.addMember(mutablePropertyVector());
unsigned count = propertyCount();
for (unsigned i = 0; i < count; ++i)
@@ -1132,7 +1115,6 @@
// See the function above if you need to update this.
struct SameSizeAsStylePropertySet : public RefCounted<SameSizeAsStylePropertySet> {
unsigned bitfield;
- void* properties;
};
COMPILE_ASSERT(sizeof(StylePropertySet) == sizeof(SameSizeAsStylePropertySet), style_property_set_should_stay_small);
@@ -1146,7 +1128,17 @@
inline void StylePropertySet::append(const CSSProperty& property)
{
ASSERT(isMutable());
- m_mutablePropertyVector->append(property);
+ mutablePropertyVector().append(property);
}
+PassRefPtr<StylePropertySet> StylePropertySet::create(CSSParserMode cssParserMode)
+{
+ return adoptRef(new MutableStylePropertySet(cssParserMode));
+}
+
+PassRefPtr<StylePropertySet> StylePropertySet::create(const CSSProperty* properties, unsigned count)
+{
+ return adoptRef(new MutableStylePropertySet(properties, count));
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/css/StylePropertySet.h (129542 => 129543)
--- trunk/Source/WebCore/css/StylePropertySet.h 2012-09-25 19:30:56 UTC (rev 129542)
+++ trunk/Source/WebCore/css/StylePropertySet.h 2012-09-25 19:55:15 UTC (rev 129543)
@@ -33,7 +33,9 @@
class CSSRule;
class CSSStyleDeclaration;
+class ImmutableStylePropertySet;
class KURL;
+class MutableStylePropertySet;
class PropertySetCSSStyleDeclaration;
class StyledElement;
class StylePropertyShorthand;
@@ -43,14 +45,12 @@
public:
~StylePropertySet();
- static PassRefPtr<StylePropertySet> create(CSSParserMode cssParserMode = CSSQuirksMode)
- {
- return adoptRef(new StylePropertySet(cssParserMode));
- }
- static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, unsigned count)
- {
- return adoptRef(new StylePropertySet(properties, count, CSSStrictMode, /* makeMutable */ true));
- }
+ // Override RefCounted's deref() to ensure operator delete is called on
+ // the appropriate subclass type.
+ void deref();
+
+ static PassRefPtr<StylePropertySet> create(CSSParserMode = CSSQuirksMode);
+ static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, unsigned count);
static PassRefPtr<StylePropertySet> createImmutable(const CSSProperty* properties, unsigned count, CSSParserMode);
unsigned propertyCount() const;
@@ -114,12 +114,33 @@
#ifndef NDEBUG
void showStyle();
#endif
+
+ const CSSProperty* immutablePropertyArray() const;
+
+protected:
+ StylePropertySet(CSSParserMode cssParserMode)
+ : m_cssParserMode(cssParserMode)
+ , m_ownsCSSOMWrapper(false)
+ , m_isMutable(true)
+ , m_arraySize(0)
+ { }
+
+ StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize)
+ : m_cssParserMode(cssParserMode)
+ , m_ownsCSSOMWrapper(false)
+ , m_isMutable(false)
+ , m_arraySize(immutableArraySize)
+ { }
+
+ Vector<CSSProperty, 4>& mutablePropertyVector();
+ const Vector<CSSProperty, 4>& mutablePropertyVector() const;
+
+ unsigned m_cssParserMode : 2;
+ mutable unsigned m_ownsCSSOMWrapper : 1;
+ mutable unsigned m_isMutable : 1;
+ unsigned m_arraySize : 28;
private:
- StylePropertySet(CSSParserMode);
- StylePropertySet(const CSSProperty* properties, unsigned count, CSSParserMode, bool makeMutable);
- StylePropertySet(const StylePropertySet&);
-
void setNeedsStyleRecalc();
String getShorthandValue(const StylePropertyShorthand&) const;
@@ -139,40 +160,63 @@
CSSProperty* findPropertyWithId(CSSPropertyID);
void append(const CSSProperty&);
- CSSProperty* array();
- const CSSProperty* array() const;
- unsigned m_cssParserMode : 2;
- mutable unsigned m_ownsCSSOMWrapper : 1;
- mutable unsigned m_isMutable : 1;
- unsigned m_arraySize : 28;
-
- union {
- Vector<CSSProperty>* m_mutablePropertyVector;
- void* m_properties;
- };
-
friend class PropertySetCSSStyleDeclaration;
};
+class ImmutableStylePropertySet : public StylePropertySet {
+public:
+ ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode);
+ ~ImmutableStylePropertySet();
+
+ void* m_propertyArray;
+};
+
+class MutableStylePropertySet : public StylePropertySet {
+public:
+ MutableStylePropertySet(CSSParserMode cssParserMode)
+ : StylePropertySet(cssParserMode)
+ { }
+ MutableStylePropertySet(const CSSProperty* properties, unsigned count);
+ MutableStylePropertySet(const StylePropertySet&);
+
+ Vector<CSSProperty, 4> m_propertyVector;
+};
+
+inline Vector<CSSProperty, 4>& StylePropertySet::mutablePropertyVector()
+{
+ ASSERT(m_isMutable);
+ return static_cast<MutableStylePropertySet*>(this)->m_propertyVector;
+}
+
+inline const Vector<CSSProperty, 4>& StylePropertySet::mutablePropertyVector() const
+{
+ ASSERT(m_isMutable);
+ return static_cast<const MutableStylePropertySet*>(this)->m_propertyVector;
+}
+
+inline const CSSProperty* StylePropertySet::immutablePropertyArray() const
+{
+ ASSERT(!m_isMutable);
+ return reinterpret_cast<const CSSProperty*>(&static_cast<const ImmutableStylePropertySet*>(this)->m_propertyArray);
+}
+
inline CSSProperty& StylePropertySet::propertyAt(unsigned index)
{
- if (isMutable())
- return m_mutablePropertyVector->at(index);
- return array()[index];
+ return mutablePropertyVector().at(index);
}
inline const CSSProperty& StylePropertySet::propertyAt(unsigned index) const
{
- if (isMutable())
- return m_mutablePropertyVector->at(index);
- return array()[index];
+ if (m_isMutable)
+ return mutablePropertyVector().at(index);
+ return immutablePropertyArray()[index];
}
inline unsigned StylePropertySet::propertyCount() const
{
- if (isMutable())
- return m_mutablePropertyVector->size();
+ if (m_isMutable)
+ return mutablePropertyVector().size();
return m_arraySize;
}
@@ -181,16 +225,15 @@
return !propertyCount();
}
-inline CSSProperty* StylePropertySet::array()
+inline void StylePropertySet::deref()
{
- ASSERT(!isMutable());
- return reinterpret_cast<CSSProperty*>(&m_properties);
-}
+ if (!derefBase())
+ return;
-inline const CSSProperty* StylePropertySet::array() const
-{
- ASSERT(!isMutable());
- return reinterpret_cast<const CSSProperty*>(&m_properties);
+ if (m_isMutable)
+ delete static_cast<MutableStylePropertySet*>(this);
+ else
+ delete static_cast<ImmutableStylePropertySet*>(this);
}
} // namespace WebCore