+2008-02-25 Anders Carlsson <andersca@apple.com>
+
+ Reviewed by Darin.
+
+ Make some of the refcounted style objects start out with a refcount of 1.
+
+ * rendering/DataRef.h:
+ Make a DeprecatedDataRef class which is just a copy of the old DataRef class.
+ Change DataRef to use ::create() and ::copy() instead of the constructors.
+ Change DataRef's pointer to be a RefPtr instead.
+
+ * rendering/RenderStyle.cpp:
+ (WebCore::StyleMarqueeData::StyleMarqueeData):
+ (WebCore::StyleFlexibleBoxData::StyleFlexibleBoxData):
+ (WebCore::StyleMultiColData::StyleMultiColData):
+ (WebCore::StyleTransformData::StyleTransformData):
+ Start with a RefCount of 1.
+
+ * rendering/RenderStyle.h:
+ * rendering/SVGRenderStyle.h:
+ Add ::create() and ::copy() methods. Make not yet converted classes use DeprecatedDataRef.
+
2008-02-25 Darin Adler <darin@apple.com>
Reviewed by Anders.
/*
- * This file is part of the DOM implementation for KDE.
- *
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* (C) 2000 Antti Koivisto (koivisto@kde.org)
* (C) 2000 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2003, 2005 Apple Computer, Inc.
+ * Copyright (C) 2003, 2005, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#ifndef DataRef_h
#define DataRef_h
+#include <wtf/RefPtr.h>
+
namespace WebCore {
template <typename T> class DataRef {
public:
- DataRef()
+ const T* get() const { return m_data.get(); }
+
+ const T& operator*() const { return *m_data; }
+ const T* operator->() const { return m_data.get(); }
+
+ T* access()
+ {
+ if (!m_data->hasOneRef())
+ m_data = m_data->copy();
+ return m_data.get();
+ }
+
+ void init()
+ {
+ ASSERT(!m_data);
+ m_data = T::create();
+ }
+
+ bool operator==(const DataRef<T>& o) const
+ {
+ ASSERT(m_data);
+ ASSERT(o.m_data);
+ return m_data == o.m_data || *m_data == *o.m_data;
+ }
+
+ bool operator!=(const DataRef<T>& o) const
+ {
+ ASSERT(m_data);
+ ASSERT(o.m_data);
+ return m_data != o.m_data && *m_data != *o.m_data;
+ }
+
+private:
+ RefPtr<T> m_data;
+};
+
+template <typename T> class DeprecatedDataRef {
+public:
+ DeprecatedDataRef()
: m_data(0)
{
}
- DataRef(const DataRef<T>& d)
+ DeprecatedDataRef(const DeprecatedDataRef<T>& d)
{
ASSERT(d.m_data);
m_data = d.m_data;
m_data->ref();
}
- ~DataRef()
+ ~DeprecatedDataRef()
{
if (m_data)
m_data->deref();
m_data->ref();
}
- DataRef<T>& operator=(const DataRef<T>& d)
+ DeprecatedDataRef<T>& operator=(const DeprecatedDataRef<T>& d)
{
ASSERT(d.m_data);
d.m_data->ref();
return *this;
}
- bool operator==(const DataRef<T>& o) const
+ bool operator==(const DeprecatedDataRef<T>& o) const
{
ASSERT(m_data);
ASSERT(o.m_data);
return m_data == o.m_data || *m_data == *o.m_data;
}
- bool operator!=(const DataRef<T>& o) const
+ bool operator!=(const DeprecatedDataRef<T>& o) const
{
ASSERT(m_data);
ASSERT(o.m_data);
}
StyleMarqueeData::StyleMarqueeData()
- : RefCounted<StyleMarqueeData>(0)
- , increment(RenderStyle::initialMarqueeIncrement())
+ : increment(RenderStyle::initialMarqueeIncrement())
, speed(RenderStyle::initialMarqueeSpeed())
, loops(RenderStyle::initialMarqueeLoopCount())
, behavior(RenderStyle::initialMarqueeBehavior())
}
StyleMarqueeData::StyleMarqueeData(const StyleMarqueeData& o)
- : RefCounted<StyleMarqueeData>(0)
+ : RefCounted<StyleMarqueeData>()
, increment(o.increment)
, speed(o.speed)
, loops(o.loops)
}
StyleFlexibleBoxData::StyleFlexibleBoxData()
- : RefCounted<StyleFlexibleBoxData>(0)
- , flex(RenderStyle::initialBoxFlex())
+ : flex(RenderStyle::initialBoxFlex())
, flex_group(RenderStyle::initialBoxFlexGroup())
, ordinal_group(RenderStyle::initialBoxOrdinalGroup())
, align(RenderStyle::initialBoxAlign())
}
StyleFlexibleBoxData::StyleFlexibleBoxData(const StyleFlexibleBoxData& o)
- : RefCounted<StyleFlexibleBoxData>(0)
+ : RefCounted<StyleFlexibleBoxData>()
, flex(o.flex)
, flex_group(o.flex_group)
, ordinal_group(o.ordinal_group)
}
StyleMultiColData::StyleMultiColData()
- : RefCounted<StyleMultiColData>(0)
- , m_width(0)
+ : m_width(0)
, m_count(RenderStyle::initialColumnCount())
, m_gap(0)
, m_autoWidth(true)
}
StyleMultiColData::StyleMultiColData(const StyleMultiColData& o)
- : RefCounted<StyleMultiColData>(0)
+ : RefCounted<StyleMultiColData>()
, m_width(o.m_width)
, m_count(o.m_count)
, m_gap(o.m_gap)
}
StyleTransformData::StyleTransformData()
- : RefCounted<StyleTransformData>(0)
- , m_operations(RenderStyle::initialTransform())
+ : m_operations(RenderStyle::initialTransform())
, m_x(RenderStyle::initialTransformOriginX())
, m_y(RenderStyle::initialTransformOriginY())
{
}
StyleTransformData::StyleTransformData(const StyleTransformData& o)
- : RefCounted<StyleTransformData>(0)
+ : RefCounted<StyleTransformData>()
, m_operations(o.m_operations)
, m_x(o.m_x)
, m_y(o.m_y)
class StyleMarqueeData : public RefCounted<StyleMarqueeData> {
public:
- StyleMarqueeData();
- StyleMarqueeData(const StyleMarqueeData& o);
+ static PassRefPtr<StyleMarqueeData> create() { return adoptRef(new StyleMarqueeData); }
+ PassRefPtr<StyleMarqueeData> copy() const { return adoptRef(new StyleMarqueeData(*this)); }
bool operator==(const StyleMarqueeData& o) const;
bool operator!=(const StyleMarqueeData& o) const {
unsigned behavior : 3; // EMarqueeBehavior
EMarqueeDirection direction : 3; // not unsigned because EMarqueeDirection has negative values
+
+private:
+ StyleMarqueeData();
+ StyleMarqueeData(const StyleMarqueeData& o);
};
// CSS3 Multi Column Layout
class StyleMultiColData : public RefCounted<StyleMultiColData> {
public:
- StyleMultiColData();
- StyleMultiColData(const StyleMultiColData& o);
-
+ static PassRefPtr<StyleMultiColData> create() { return adoptRef(new StyleMultiColData); }
+ PassRefPtr<StyleMultiColData> copy() const { return adoptRef(new StyleMultiColData(*this)); }
+
bool operator==(const StyleMultiColData& o) const;
bool operator!=(const StyleMultiColData &o) const {
return !(*this == o);
unsigned m_breakBefore : 2; // EPageBreak
unsigned m_breakAfter : 2; // EPageBreak
unsigned m_breakInside : 2; // EPageBreak
+
+private:
+ StyleMultiColData();
+ StyleMultiColData(const StyleMultiColData& o);
};
// CSS Transforms (may become part of CSS3)
class StyleTransformData : public RefCounted<StyleTransformData> {
public:
- StyleTransformData();
- StyleTransformData(const StyleTransformData&);
+ static PassRefPtr<StyleTransformData> create() { return adoptRef(new StyleTransformData); }
+ PassRefPtr<StyleTransformData> copy() const { return adoptRef(new StyleTransformData(*this)); }
bool operator==(const StyleTransformData&) const;
bool operator!=(const StyleTransformData& o) const {
TransformOperations m_operations;
Length m_x;
Length m_y;
+
+private:
+ StyleTransformData();
+ StyleTransformData(const StyleTransformData&);
};
//------------------------------------------------
class StyleFlexibleBoxData : public RefCounted<StyleFlexibleBoxData> {
public:
- StyleFlexibleBoxData();
- StyleFlexibleBoxData(const StyleFlexibleBoxData& o);
-
+ static PassRefPtr<StyleFlexibleBoxData> create() { return adoptRef(new StyleFlexibleBoxData); }
+ PassRefPtr<StyleFlexibleBoxData> copy() const { return adoptRef(new StyleFlexibleBoxData(*this)); }
+
bool operator==(const StyleFlexibleBoxData& o) const;
bool operator!=(const StyleFlexibleBoxData &o) const {
return !(*this == o);
unsigned pack: 3; // EBoxAlignment
unsigned orient: 1; // EBoxOrient
unsigned lines : 1; // EBoxLines
+
+private:
+ StyleFlexibleBoxData();
+ StyleFlexibleBoxData(const StyleFlexibleBoxData& o);
};
// This struct holds information about shadows for the text-shadow and box-shadow properties.
} noninherited_flags;
// non-inherited attributes
- DataRef<StyleBoxData> box;
- DataRef<StyleVisualData> visual;
- DataRef<StyleBackgroundData> background;
- DataRef<StyleSurroundData> surround;
- DataRef<StyleRareNonInheritedData> rareNonInheritedData;
+ DeprecatedDataRef<StyleBoxData> box;
+ DeprecatedDataRef<StyleVisualData> visual;
+ DeprecatedDataRef<StyleBackgroundData> background;
+ DeprecatedDataRef<StyleSurroundData> surround;
+ DeprecatedDataRef<StyleRareNonInheritedData> rareNonInheritedData;
// inherited attributes
- DataRef<StyleRareInheritedData> rareInheritedData;
- DataRef<StyleInheritedData> inherited;
+ DeprecatedDataRef<StyleRareInheritedData> rareInheritedData;
+ DeprecatedDataRef<StyleInheritedData> inherited;
// list of associated pseudo styles
RenderStyle* pseudoStyle;
int m_ref;
#if ENABLE(SVG)
- DataRef<SVGRenderStyle> m_svgStyle;
+ DeprecatedDataRef<SVGRenderStyle> m_svgStyle;
#endif
// !END SYNC!
} svg_noninherited_flags;
// inherited attributes
- DataRef<StyleFillData> fill;
- DataRef<StyleStrokeData> stroke;
- DataRef<StyleMarkerData> markers;
- DataRef<StyleTextData> text;
+ DeprecatedDataRef<StyleFillData> fill;
+ DeprecatedDataRef<StyleStrokeData> stroke;
+ DeprecatedDataRef<StyleMarkerData> markers;
+ DeprecatedDataRef<StyleTextData> text;
// non-inherited attributes
- DataRef<StyleStopData> stops;
- DataRef<StyleClipData> clip;
- DataRef<StyleMaskData> mask;
- DataRef<StyleMiscData> misc;
+ DeprecatedDataRef<StyleStopData> stops;
+ DeprecatedDataRef<StyleClipData> clip;
+ DeprecatedDataRef<StyleMaskData> mask;
+ DeprecatedDataRef<StyleMiscData> misc;
// static default style
static SVGRenderStyle *s_defaultStyle;