Skip to content
Permalink
Browse files
DataRef<T> should use Ref<T> internally.
<https://webkit.org/b/122953>

DataRef is used to hold RenderStyle substructures, and due to the
way style inheritance is implemented, DataRef will always point to
a live object.

Codify this by making DataRef::m_data a Ref, and making all methods
that create substructure objects return PassRef.

Reviewed by Antti Koivisto.

Canonical link: https://commits.webkit.org/141030@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157568 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Oct 17, 2013
1 parent 5972fec commit af8f86932280c4c63396e4f485bc5a6df2fec6a8
Showing with 140 additions and 127 deletions.
  1. +14 −0 Source/WebCore/ChangeLog
  2. +11 −16 Source/WebCore/rendering/style/DataRef.h
  3. +4 −5 Source/WebCore/rendering/style/NinePieceImage.cpp
  4. +2 −2 Source/WebCore/rendering/style/NinePieceImage.h
  5. +8 −21 Source/WebCore/rendering/style/RenderStyle.cpp
  6. +37 −30 Source/WebCore/rendering/style/SVGRenderStyle.cpp
  7. +3 −2 Source/WebCore/rendering/style/SVGRenderStyle.h
  8. +16 −16 Source/WebCore/rendering/style/SVGRenderStyleDefs.h
  9. +2 −2 Source/WebCore/rendering/style/StyleBackgroundData.h
  10. +2 −2 Source/WebCore/rendering/style/StyleBoxData.h
  11. +2 −2 Source/WebCore/rendering/style/StyleDeprecatedFlexibleBoxData.h
  12. +2 −2 Source/WebCore/rendering/style/StyleFilterData.h
  13. +2 −2 Source/WebCore/rendering/style/StyleFlexibleBoxData.h
  14. +2 −2 Source/WebCore/rendering/style/StyleGridData.h
  15. +2 −2 Source/WebCore/rendering/style/StyleGridItemData.h
  16. +2 −2 Source/WebCore/rendering/style/StyleInheritedData.h
  17. +2 −2 Source/WebCore/rendering/style/StyleMarqueeData.h
  18. +2 −2 Source/WebCore/rendering/style/StyleMultiColData.h
  19. +3 −3 Source/WebCore/rendering/style/StyleRareInheritedData.cpp
  20. +2 −2 Source/WebCore/rendering/style/StyleRareInheritedData.h
  21. +10 −0 Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp
  22. +2 −2 Source/WebCore/rendering/style/StyleRareNonInheritedData.h
  23. +2 −2 Source/WebCore/rendering/style/StyleSurroundData.h
  24. +2 −2 Source/WebCore/rendering/style/StyleTransformData.h
  25. +2 −2 Source/WebCore/rendering/style/StyleVariableData.h
  26. +2 −2 Source/WebCore/rendering/style/StyleVisualData.h
@@ -1,3 +1,17 @@
2013-10-17 Andreas Kling <akling@apple.com>

DataRef<T> should use Ref<T> internally.
<https://webkit.org/b/122953>

DataRef is used to hold RenderStyle substructures, and due to the
way style inheritance is implemented, DataRef will always point to
a live object.

Codify this by making DataRef::m_data a Ref, and making all methods
that create substructure objects return PassRef.

Reviewed by Antti Koivisto.

2013-10-17 Mihnea Ovidenie <mihnea@adobe.com>

[CSS Regions] Anonymous nested regions
@@ -24,13 +24,18 @@
#ifndef DataRef_h
#define DataRef_h

#include <wtf/RefPtr.h>
#include <wtf/PassRef.h>
#include <wtf/Ref.h>

namespace WebCore {

template <typename T> class DataRef {
public:
const T* get() const { return m_data.get(); }
DataRef(PassRef<T> data) : m_data(std::move(data)) { }
DataRef(const DataRef& other) : m_data(const_cast<T&>(other.m_data.get())) { }
DataRef& operator=(const DataRef& other) { m_data = const_cast<T&>(other.m_data.get()); return *this; }

const T* get() const { return &m_data.get(); }

const T& operator*() const { return *get(); }
const T* operator->() const { return get(); }
@@ -39,31 +44,21 @@ template <typename T> class DataRef {
{
if (!m_data->hasOneRef())
m_data = m_data->copy();
return m_data.get();
}

void init()
{
ASSERT(!m_data);
m_data = T::create();
return &m_data.get();
}

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;
return &m_data.get() == &o.m_data.get() || m_data.get() == o.m_data.get();
}

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;
return &m_data.get() != &o.m_data.get() && m_data.get() != o.m_data.get();
}

private:
RefPtr<T> m_data;
Ref<T> m_data;
};

} // namespace WebCore
@@ -23,15 +23,14 @@

#include "config.h"
#include "NinePieceImage.h"
#include <wtf/NeverDestroyed.h>

namespace WebCore {

static DataRef<NinePieceImageData>& defaultData()
{
static DataRef<NinePieceImageData>* data = new DataRef<NinePieceImageData>;
if (!data->get())
data->init();
return *data;
static NeverDestroyed<DataRef<NinePieceImageData>> data(NinePieceImageData::create());
return data.get();
}

NinePieceImage::NinePieceImage()
@@ -40,8 +39,8 @@ NinePieceImage::NinePieceImage()
}

NinePieceImage::NinePieceImage(PassRefPtr<StyleImage> image, LengthBox imageSlices, bool fill, LengthBox borderSlices, LengthBox outset, ENinePieceImageRule horizontalRule, ENinePieceImageRule verticalRule)
: m_data(NinePieceImageData::create())
{
m_data.init();
m_data.access()->image = image;
m_data.access()->imageSlices = std::move(imageSlices);
m_data.access()->borderSlices = std::move(borderSlices);
@@ -37,8 +37,8 @@ enum ENinePieceImageRule {

class NinePieceImageData : public RefCounted<NinePieceImageData> {
public:
static PassRefPtr<NinePieceImageData> create() { return adoptRef(new NinePieceImageData); }
PassRefPtr<NinePieceImageData> copy() const { return adoptRef(new NinePieceImageData(*this)); }
static PassRef<NinePieceImageData> create() { return adoptRef(*new NinePieceImageData); }
PassRef<NinePieceImageData> copy() const { return adoptRef(*new NinePieceImageData(*this)); }

bool operator==(const NinePieceImageData&) const;
bool operator!=(const NinePieceImageData& o) const { return !(*this == o); }
@@ -128,29 +128,16 @@ ALWAYS_INLINE RenderStyle::RenderStyle()
}

ALWAYS_INLINE RenderStyle::RenderStyle(bool)
: m_box(StyleBoxData::create())
, visual(StyleVisualData::create())
, m_background(StyleBackgroundData::create())
, surround(StyleSurroundData::create())
, rareNonInheritedData(StyleRareNonInheritedData::create())
, rareInheritedData(StyleRareInheritedData::create())
, inherited(StyleInheritedData::create())
, m_svgStyle(SVGRenderStyle::create())
{
setBitDefaults();

m_box.init();
visual.init();
m_background.init();
surround.init();
rareNonInheritedData.init();
rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
rareNonInheritedData.access()->m_flexibleBox.init();
rareNonInheritedData.access()->m_marquee.init();
rareNonInheritedData.access()->m_multiCol.init();
rareNonInheritedData.access()->m_transform.init();
#if ENABLE(CSS_FILTERS)
rareNonInheritedData.access()->m_filter.init();
#endif
rareNonInheritedData.access()->m_grid.init();
rareNonInheritedData.access()->m_gridItem.init();
rareInheritedData.init();
inherited.init();
#if ENABLE(SVG)
m_svgStyle.init();
#endif
}

ALWAYS_INLINE RenderStyle::RenderStyle(const RenderStyle& o)
@@ -35,55 +35,62 @@
#include "IntRect.h"
#include "NodeRenderStyle.h"
#include "SVGElement.h"
#include <wtf/NeverDestroyed.h>

using namespace std;

namespace WebCore {

SVGRenderStyle::SVGRenderStyle()
static const SVGRenderStyle& defaultSVGStyle()
{
static SVGRenderStyle* defaultStyle = new SVGRenderStyle(CreateDefault);
static NeverDestroyed<DataRef<SVGRenderStyle>> style(SVGRenderStyle::createDefaultStyle());
return *style.get().get();
}

fill = defaultStyle->fill;
stroke = defaultStyle->stroke;
text = defaultStyle->text;
stops = defaultStyle->stops;
misc = defaultStyle->misc;
shadowSVG = defaultStyle->shadowSVG;
inheritedResources = defaultStyle->inheritedResources;
resources = defaultStyle->resources;
PassRef<SVGRenderStyle> SVGRenderStyle::createDefaultStyle()
{
return adoptRef(*new SVGRenderStyle(CreateDefault));
}

SVGRenderStyle::SVGRenderStyle()
: fill(defaultSVGStyle().fill)
, stroke(defaultSVGStyle().stroke)
, text(defaultSVGStyle().text)
, inheritedResources(defaultSVGStyle().inheritedResources)
, stops(defaultSVGStyle().stops)
, misc(defaultSVGStyle().misc)
, shadowSVG(defaultSVGStyle().shadowSVG)
, resources(defaultSVGStyle().resources)
{
setBitDefaults();
}

SVGRenderStyle::SVGRenderStyle(CreateDefaultType)
: fill(StyleFillData::create())
, stroke(StyleStrokeData::create())
, text(StyleTextData::create())
, inheritedResources(StyleInheritedResourceData::create())
, stops(StyleStopData::create())
, misc(StyleMiscData::create())
, shadowSVG(StyleShadowSVGData::create())
, resources(StyleResourceData::create())
{
setBitDefaults();

fill.init();
stroke.init();
text.init();
stops.init();
misc.init();
shadowSVG.init();
inheritedResources.init();
resources.init();
}

SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle& other)
: RefCounted<SVGRenderStyle>()
, svg_inherited_flags(other.svg_inherited_flags)
, svg_noninherited_flags(other.svg_noninherited_flags)
, fill(other.fill)
, stroke(other.stroke)
, text(other.text)
, inheritedResources(other.inheritedResources)
, stops(other.stops)
, misc(other.misc)
, shadowSVG(other.shadowSVG)
, resources(other.resources)
{
fill = other.fill;
stroke = other.stroke;
text = other.text;
stops = other.stops;
misc = other.misc;
shadowSVG = other.shadowSVG;
inheritedResources = other.inheritedResources;
resources = other.resources;

svg_inherited_flags = other.svg_inherited_flags;
svg_noninherited_flags = other.svg_noninherited_flags;
}

SVGRenderStyle::~SVGRenderStyle()
@@ -41,8 +41,9 @@ class RenderObject;

class SVGRenderStyle : public RefCounted<SVGRenderStyle> {
public:
static PassRefPtr<SVGRenderStyle> create() { return adoptRef(new SVGRenderStyle); }
PassRefPtr<SVGRenderStyle> copy() const { return adoptRef(new SVGRenderStyle(*this));}
static PassRef<SVGRenderStyle> createDefaultStyle();
static PassRef<SVGRenderStyle> create() { return adoptRef(*new SVGRenderStyle); }
PassRef<SVGRenderStyle> copy() const { return adoptRef(*new SVGRenderStyle(*this));}
~SVGRenderStyle();

bool inheritedNotEqual(const SVGRenderStyle*) const;
@@ -101,8 +101,8 @@ namespace WebCore {
// Inherited/Non-Inherited Style Datastructures
class StyleFillData : public RefCounted<StyleFillData> {
public:
static PassRefPtr<StyleFillData> create() { return adoptRef(new StyleFillData); }
PassRefPtr<StyleFillData> copy() const { return adoptRef(new StyleFillData(*this)); }
static PassRef<StyleFillData> create() { return adoptRef(*new StyleFillData); }
PassRef<StyleFillData> copy() const { return adoptRef(*new StyleFillData(*this)); }

bool operator==(const StyleFillData&) const;
bool operator!=(const StyleFillData& other) const
@@ -125,8 +125,8 @@ namespace WebCore {

class StyleStrokeData : public RefCounted<StyleStrokeData> {
public:
static PassRefPtr<StyleStrokeData> create() { return adoptRef(new StyleStrokeData); }
PassRefPtr<StyleStrokeData> copy() const { return adoptRef(new StyleStrokeData(*this)); }
static PassRef<StyleStrokeData> create() { return adoptRef(*new StyleStrokeData); }
PassRef<StyleStrokeData> copy() const { return adoptRef(*new StyleStrokeData(*this)); }

bool operator==(const StyleStrokeData&) const;
bool operator!=(const StyleStrokeData& other) const
@@ -155,8 +155,8 @@ namespace WebCore {

class StyleStopData : public RefCounted<StyleStopData> {
public:
static PassRefPtr<StyleStopData> create() { return adoptRef(new StyleStopData); }
PassRefPtr<StyleStopData> copy() const { return adoptRef(new StyleStopData(*this)); }
static PassRef<StyleStopData> create() { return adoptRef(*new StyleStopData); }
PassRef<StyleStopData> copy() const { return adoptRef(*new StyleStopData(*this)); }

bool operator==(const StyleStopData&) const;
bool operator!=(const StyleStopData& other) const
@@ -174,8 +174,8 @@ namespace WebCore {

class StyleTextData : public RefCounted<StyleTextData> {
public:
static PassRefPtr<StyleTextData> create() { return adoptRef(new StyleTextData); }
PassRefPtr<StyleTextData> copy() const { return adoptRef(new StyleTextData(*this)); }
static PassRef<StyleTextData> create() { return adoptRef(*new StyleTextData); }
PassRef<StyleTextData> copy() const { return adoptRef(*new StyleTextData(*this)); }

bool operator==(const StyleTextData& other) const;
bool operator!=(const StyleTextData& other) const
@@ -193,8 +193,8 @@ namespace WebCore {
// Note: the rule for this class is, *no inheritance* of these props
class StyleMiscData : public RefCounted<StyleMiscData> {
public:
static PassRefPtr<StyleMiscData> create() { return adoptRef(new StyleMiscData); }
PassRefPtr<StyleMiscData> copy() const { return adoptRef(new StyleMiscData(*this)); }
static PassRef<StyleMiscData> create() { return adoptRef(*new StyleMiscData); }
PassRef<StyleMiscData> copy() const { return adoptRef(*new StyleMiscData(*this)); }

bool operator==(const StyleMiscData&) const;
bool operator!=(const StyleMiscData& other) const
@@ -216,8 +216,8 @@ namespace WebCore {

class StyleShadowSVGData : public RefCounted<StyleShadowSVGData> {
public:
static PassRefPtr<StyleShadowSVGData> create() { return adoptRef(new StyleShadowSVGData); }
PassRefPtr<StyleShadowSVGData> copy() const { return adoptRef(new StyleShadowSVGData(*this)); }
static PassRef<StyleShadowSVGData> create() { return adoptRef(*new StyleShadowSVGData); }
PassRef<StyleShadowSVGData> copy() const { return adoptRef(*new StyleShadowSVGData(*this)); }

bool operator==(const StyleShadowSVGData&) const;
bool operator!=(const StyleShadowSVGData& other) const
@@ -235,8 +235,8 @@ namespace WebCore {
// Non-inherited resources
class StyleResourceData : public RefCounted<StyleResourceData> {
public:
static PassRefPtr<StyleResourceData> create() { return adoptRef(new StyleResourceData); }
PassRefPtr<StyleResourceData> copy() const { return adoptRef(new StyleResourceData(*this)); }
static PassRef<StyleResourceData> create() { return adoptRef(*new StyleResourceData); }
PassRef<StyleResourceData> copy() const { return adoptRef(*new StyleResourceData(*this)); }

bool operator==(const StyleResourceData&) const;
bool operator!=(const StyleResourceData& other) const
@@ -256,8 +256,8 @@ namespace WebCore {
// Inherited resources
class StyleInheritedResourceData : public RefCounted<StyleInheritedResourceData> {
public:
static PassRefPtr<StyleInheritedResourceData> create() { return adoptRef(new StyleInheritedResourceData); }
PassRefPtr<StyleInheritedResourceData> copy() const { return adoptRef(new StyleInheritedResourceData(*this)); }
static PassRef<StyleInheritedResourceData> create() { return adoptRef(*new StyleInheritedResourceData); }
PassRef<StyleInheritedResourceData> copy() const { return adoptRef(*new StyleInheritedResourceData(*this)); }

bool operator==(const StyleInheritedResourceData&) const;
bool operator!=(const StyleInheritedResourceData& other) const
@@ -35,8 +35,8 @@ namespace WebCore {

class StyleBackgroundData : public RefCounted<StyleBackgroundData> {
public:
static PassRefPtr<StyleBackgroundData> create() { return adoptRef(new StyleBackgroundData); }
PassRefPtr<StyleBackgroundData> copy() const { return adoptRef(new StyleBackgroundData(*this)); }
static PassRef<StyleBackgroundData> create() { return adoptRef(*new StyleBackgroundData); }
PassRef<StyleBackgroundData> copy() const { return adoptRef(*new StyleBackgroundData(*this)); }
~StyleBackgroundData() { }

bool operator==(const StyleBackgroundData& o) const;
@@ -34,8 +34,8 @@ namespace WebCore {

class StyleBoxData : public RefCounted<StyleBoxData> {
public:
static PassRefPtr<StyleBoxData> create() { return adoptRef(new StyleBoxData); }
PassRefPtr<StyleBoxData> copy() const { return adoptRef(new StyleBoxData(*this)); }
static PassRef<StyleBoxData> create() { return adoptRef(*new StyleBoxData); }
PassRef<StyleBoxData> copy() const { return adoptRef(*new StyleBoxData(*this)); }

bool operator==(const StyleBoxData& o) const;
bool operator!=(const StyleBoxData& o) const
@@ -32,8 +32,8 @@ namespace WebCore {

class StyleDeprecatedFlexibleBoxData : public RefCounted<StyleDeprecatedFlexibleBoxData> {
public:
static PassRefPtr<StyleDeprecatedFlexibleBoxData> create() { return adoptRef(new StyleDeprecatedFlexibleBoxData); }
PassRefPtr<StyleDeprecatedFlexibleBoxData> copy() const { return adoptRef(new StyleDeprecatedFlexibleBoxData(*this)); }
static PassRef<StyleDeprecatedFlexibleBoxData> create() { return adoptRef(*new StyleDeprecatedFlexibleBoxData); }
PassRef<StyleDeprecatedFlexibleBoxData> copy() const { return adoptRef(*new StyleDeprecatedFlexibleBoxData(*this)); }

bool operator==(const StyleDeprecatedFlexibleBoxData&) const;
bool operator!=(const StyleDeprecatedFlexibleBoxData& o) const
@@ -36,8 +36,8 @@ namespace WebCore {

class StyleFilterData : public RefCounted<StyleFilterData> {
public:
static PassRefPtr<StyleFilterData> create() { return adoptRef(new StyleFilterData); }
PassRefPtr<StyleFilterData> copy() const { return adoptRef(new StyleFilterData(*this)); }
static PassRef<StyleFilterData> create() { return adoptRef(*new StyleFilterData); }
PassRef<StyleFilterData> copy() const { return adoptRef(*new StyleFilterData(*this)); }

bool operator==(const StyleFilterData&) const;
bool operator!=(const StyleFilterData& o) const

0 comments on commit af8f869

Please sign in to comment.