[webkit-changes] cvs commit: WebCore/khtml/rendering
render_replaced.cpp render_replaced.h
Darin
darin at opensource.apple.com
Thu Dec 8 00:54:41 PST 2005
darin 05/12/08 00:54:41
Modified: . ChangeLog
khtml/misc shared.h
khtml/rendering render_replaced.cpp render_replaced.h
Log:
Reviewed by Eric.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5686
make Shared::deref faster by eliminating multiple branches
* khtml/misc/shared.h: Rewrote both Shared and TreeShared to be functionally
the same, but used signed reference counts and remove the extra
check inside deref that handles the case of extra derefs (a programming
mistake in any case). This elimnates a branch from a hot code path.
Also added license header. New versions have private data members, unlike
the old ones that used protected.
* khtml/rendering/render_replaced.h: Removed private inheritance from
Shared, and instead just declared a variable that holds a reference count,
because that's the only thing that was being used from Shared.
* khtml/rendering/render_replaced.cpp:
(RenderWidget::RenderWidget): Initialized m_refCount.
(RenderWidget::~RenderWidget): Use m_refCount.
(RenderWidget::eventFilter): Ditto.
(RenderWidget::deref): Use m_refCount and the new faster idiom (although here
it's not important becaue the function isn't even inlined).
Revision Changes Path
1.491 +24 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.490
retrieving revision 1.491
diff -u -r1.490 -r1.491
--- ChangeLog 8 Dec 2005 08:44:46 -0000 1.490
+++ ChangeLog 8 Dec 2005 08:54:38 -0000 1.491
@@ -1,3 +1,27 @@
+2005-12-08 Darin Adler <darin at apple.com>
+
+ Reviewed by Eric.
+
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5686
+ make Shared::deref faster by eliminating multiple branches
+
+ * khtml/misc/shared.h: Rewrote both Shared and TreeShared to be functionally
+ the same, but used signed reference counts and remove the extra
+ check inside deref that handles the case of extra derefs (a programming
+ mistake in any case). This elimnates a branch from a hot code path.
+ Also added license header. New versions have private data members, unlike
+ the old ones that used protected.
+
+ * khtml/rendering/render_replaced.h: Removed private inheritance from
+ Shared, and instead just declared a variable that holds a reference count,
+ because that's the only thing that was being used from Shared.
+ * khtml/rendering/render_replaced.cpp:
+ (RenderWidget::RenderWidget): Initialized m_refCount.
+ (RenderWidget::~RenderWidget): Use m_refCount.
+ (RenderWidget::eventFilter): Ditto.
+ (RenderWidget::deref): Use m_refCount and the new faster idiom (although here
+ it's not important becaue the function isn't even inlined).
+
2005-12-08 Eric Seidel <eseidel at apple.com>
No review needed, build fix only.
1.11 +50 -44 WebCore/khtml/misc/shared.h
Index: shared.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/misc/shared.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- shared.h 1 Dec 2005 10:32:23 -0000 1.10
+++ shared.h 8 Dec 2005 08:54:40 -0000 1.11
@@ -1,65 +1,71 @@
-#ifndef SHARED_H
-#define SHARED_H
+/*
+ This file is part of the KDE libraries
+
+ Copyright (C) 2005 Apple Computer, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KHTML_SHARED_H
+#define KHTML_SHARED_H
#include <kxmlcore/RefPtr.h>
namespace khtml {
-template<class type> class Shared
+template<class T> class Shared
{
public:
- Shared() { _ref=0; /*counter++;*/ }
- ~Shared() { /*counter--;*/ }
+ Shared() : m_refCount(0) { }
- void ref() { _ref++; }
- void deref() {
- if(_ref) _ref--;
- if(!_ref)
- delete static_cast<type *>(this);
- }
- bool hasOneRef() { //kdDebug(300) << "ref=" << _ref << endl;
- return _ref==1; }
-
- int refCount() const { return _ref; }
-// static int counter;
-protected:
- unsigned int _ref;
+ void ref() { ++m_refCount; }
+ void deref() { if (--m_refCount <= 0) delete static_cast<T*>(this); }
+ bool hasOneRef() { return m_refCount == 1; }
+ int refCount() const { return m_refCount; }
private:
- Shared(const Shared &);
- Shared &operator=(const Shared &);
+ int m_refCount;
+
+ Shared(const Shared&);
+ Shared& operator=(const Shared&);
};
-template<class type> class TreeShared
+template<class T> class TreeShared
{
public:
- TreeShared() { _ref = 0; m_parent = 0; /*counter++;*/ }
- TreeShared( type *parent ) { _ref=0; m_parent = parent; /*counter++;*/ }
- virtual ~TreeShared() { /*counter--;*/ }
-
- virtual void removedLastRef() { delete static_cast<type *>(this); }
- void ref() { _ref++; }
- void deref() {
- if(_ref) _ref--;
- if(!_ref && !m_parent)
- removedLastRef();
- }
- bool hasOneRef() { //kdDebug(300) << "ref=" << _ref << endl;
- return _ref==1; }
+ TreeShared() : m_refCount(0), m_parent(0) { }
+ TreeShared(T* parent) : m_refCount(0), m_parent(parent) { }
+ virtual ~TreeShared() { }
+
+ virtual void removedLastRef() { delete static_cast<T*>(this); }
+
+ void ref() { ++m_refCount; }
+ void deref() { if (--m_refCount <= 0 && !m_parent) removedLastRef(); }
+ bool hasOneRef() { return m_refCount == 1; }
+ int refCount() const { return m_refCount; }
- int refCount() const { return _ref; }
-// static int counter;
+ void setParent(T* parent) { m_parent = parent; }
+ T* parent() const { return m_parent; }
- void setParent(type *parent) { m_parent = parent; }
- type *parent() const { return m_parent; }
private:
- unsigned int _ref;
-protected:
- type *m_parent;
+ int m_refCount;
+ T* m_parent;
-private:
- TreeShared(const TreeShared &);
- TreeShared &operator=(const TreeShared &);
+ TreeShared(const TreeShared&);
+ TreeShared& operator=(const TreeShared&);
};
}
1.96 +5 -5 WebCore/khtml/rendering/render_replaced.cpp
Index: render_replaced.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/rendering/render_replaced.cpp,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- render_replaced.cpp 3 Dec 2005 01:06:45 -0000 1.95
+++ render_replaced.cpp 8 Dec 2005 08:54:40 -0000 1.96
@@ -220,7 +220,8 @@
RenderWidget::RenderWidget(DOM::NodeImpl* node)
: RenderReplaced(node),
- m_deleteWidget(false)
+ m_deleteWidget(false),
+ m_refCount(0)
{
m_widget = 0;
// a replaced element doesn't support being anonymous
@@ -278,7 +279,7 @@
RenderWidget::~RenderWidget()
{
- KHTMLAssert( refCount() <= 0 );
+ KHTMLAssert(m_refCount <= 0);
if (m_deleteWidget)
delete m_widget;
@@ -461,7 +462,7 @@
elem->deref();
// stop processing if the widget gets deleted, but continue in all other cases
- if (hasOneRef())
+ if (m_refCount == 1)
filtered = true;
deref(arena);
@@ -470,8 +471,7 @@
void RenderWidget::deref(RenderArena *arena)
{
- if (_ref) _ref--;
- if (!_ref)
+ if (--m_refCount <= 0)
arenaDelete(arena, this);
}
1.38 +3 -2 WebCore/khtml/rendering/render_replaced.h
Index: render_replaced.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/rendering/render_replaced.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- render_replaced.h 21 Nov 2005 01:20:27 -0000 1.37
+++ render_replaced.h 8 Dec 2005 08:54:40 -0000 1.38
@@ -74,7 +74,7 @@
};
-class RenderWidget : public QObject, public RenderReplaced, private khtml::Shared<RenderWidget>
+class RenderWidget : public QObject, public RenderReplaced
{
Q_OBJECT
public:
@@ -93,7 +93,7 @@
QWidget *widget() const { return m_widget; }
KHTMLView* view() const { return m_view; }
- RenderArena *ref() { _ref++; return renderArena(); }
+ RenderArena *ref() { ++m_refCount; return renderArena(); }
void deref(RenderArena *arena);
virtual void setSelectionState(SelectionState s);
@@ -113,6 +113,7 @@
bool m_deleteWidget;
QWidget *m_widget;
KHTMLView* m_view;
+ int m_refCount;
};
};
More information about the webkit-changes
mailing list