[webkit-changes] cvs commit: WebCore/khtml/rendering DataRef.h render_style.cpp render_style.h

Darin darin at opensource.apple.com
Thu Dec 22 08:46:40 PST 2005


darin       05/12/22 08:46:40

  Modified:    .        ChangeLog
               khtml/rendering DataRef.h render_style.cpp render_style.h
  Log:
          Reviewed by Eric.
  
          - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6167
            RenderStyle default constructor should initialize its members for speed
  
          * khtml/rendering/DataRef.h: (khtml::DataRef::operator=): Eliminate an extra
          branch by doing ref before deref instead of == check.
  
          * khtml/rendering/render_style.cpp:
          (khtml::initDefaultStyle): Added. Function to initialize the default style
          for use in constructor.
          (khtml::RenderStyle::RenderStyle): Changed constructor to initalize all the
          members with constructor syntax instead of using assignment on all of them.
          * khtml/rendering/render_style.h: Removed static data member _default --
          it's now a file scope global instead.
  
  Revision  Changes    Path
  1.24      +18 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ChangeLog	22 Dec 2005 04:11:35 -0000	1.23
  +++ ChangeLog	22 Dec 2005 16:46:38 -0000	1.24
  @@ -1,3 +1,21 @@
  +2005-12-22  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Eric.
  +
  +        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6167
  +          RenderStyle default constructor should initialize its members for speed
  +
  +        * khtml/rendering/DataRef.h: (khtml::DataRef::operator=): Eliminate an extra
  +        branch by doing ref before deref instead of == check.
  +
  +        * khtml/rendering/render_style.cpp:
  +        (khtml::initDefaultStyle): Added. Function to initialize the default style
  +        for use in constructor.
  +        (khtml::RenderStyle::RenderStyle): Changed constructor to initalize all the
  +        members with constructor syntax instead of using assignment on all of them.
  +        * khtml/rendering/render_style.h: Removed static data member _default --
  +        it's now a file scope global instead.
  +
   2005-12-21  Darin Adler  <darin at apple.com>
   
           Reviewed by Justin.
  
  
  
  1.3       +35 -37    WebCore/khtml/rendering/DataRef.h
  
  Index: DataRef.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/DataRef.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DataRef.h	11 Dec 2005 09:26:13 -0000	1.2
  +++ DataRef.h	22 Dec 2005 16:46:38 -0000	1.3
  @@ -23,83 +23,81 @@
    *
    */
   
  -#ifndef KHTML_DataRef_H
  -#define KHTML_DataRef_H
  +#ifndef KHTML_DATAREF_H
  +#define KHTML_DATAREF_H
  +
  +#include <assert.h>
   
   namespace khtml {
   
  -template <class DATA>
  -class DataRef
  +template <typename T> class DataRef
   {
   public:
  -
       DataRef() : m_data(0) { }
  -    
  -    DataRef(const DataRef<DATA>& d)
  +
  +    DataRef(const DataRef<T>& d)
       {
  -    	m_data = d.m_data;
  -	m_data->ref();
  +    	assert(d.m_data);
  +        m_data = d.m_data;
  +        m_data->ref();
       }
   
       ~DataRef()
       {
  -    	if(m_data)
  +    	if (m_data)
               m_data->deref();
       }
   
  -    const DATA* operator->() const
  -    {
  -    	return m_data;
  -    }
  +    const T* get() const { return m_data; }
   
  -    const DATA* get() const
  -    {
  -    	return m_data;
  -    }
  +    T& operator*() const { return *m_data; }
  +    const T* operator->() const { return m_data; }
   
  -    DATA* access()
  +    T* access()
       {
       	if (!m_data->hasOneRef()) {
   	    m_data->deref();
  -	    m_data = new DATA(*m_data);
  +	    m_data = new T(*m_data);
   	    m_data->ref();
  -	}
  -	return m_data;
  +        }
  +        return m_data;
       }
   
       void init()
       {
  -    	m_data = new DATA;
  -	m_data->ref();
  +    	assert(!m_data);
  +        m_data = new T;
  +        m_data->ref();
       }
   
  -    DataRef<DATA>& operator=(const DataRef<DATA>& d)
  +    DataRef<T>& operator=(const DataRef<T>& d)
       {
  -    	if (m_data == d.m_data)
  -	    return *this;
  +    	assert(d.m_data);
  +        d.m_data->ref();
       	if (m_data)
       	    m_data->deref();
       	m_data = d.m_data;
  -	m_data->ref();
  -
  -	return *this;
  +        return *this;
       }
   
  -    bool operator == (const DataRef<DATA>& o) const
  +    bool operator==(const DataRef<T>& o) const
       {
  -	return ((m_data == o.m_data) || (*m_data == *(o.m_data)));
  +    	assert(m_data);
  +    	assert(o.m_data);
  +        return m_data == o.m_data || *m_data == *o.m_data;
       }
       
  -    bool operator != (const DataRef<DATA>& o) const
  +    bool operator!=(const DataRef<T>& o) const
       {
  -	return ((m_data != o.m_data) && (*m_data != *(o.m_data)));
  +    	assert(m_data);
  +    	assert(o.m_data);
  +        return m_data != o.m_data && *m_data != *o.m_data;
       }
   
   private:
  -    DATA* m_data;
  +    T* m_data;
   };
   
  -};
  +}
   
   #endif
  -
  
  
  
  1.80      +27 -26    WebCore/khtml/rendering/render_style.cpp
  
  Index: render_style.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_style.cpp,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- render_style.cpp	11 Dec 2005 09:26:15 -0000	1.79
  +++ render_style.cpp	22 Dec 2005 16:46:39 -0000	1.80
  @@ -34,10 +34,11 @@
   
   #include "kdebug.h"
   
  -using namespace khtml;
  +using namespace DOM;
   
  -using DOM::DOMStringImpl;
  -using DOM::DOMString;
  +namespace khtml {
  +
  +static RenderStyle *defaultStyle;
   
   StyleSurroundData::StyleSurroundData()
       : margin( Fixed ), padding( Auto )
  @@ -512,31 +513,32 @@
       arena->free(*(size_t *)this, this);
   }
   
  -RenderStyle::RenderStyle()
  -:m_pseudoState(PseudoUnknown), m_affectedByAttributeSelectors(false)
  +inline RenderStyle *initDefaultStyle()
   {
  -    m_ref = 0;
  -    
  -    if (!_default)
  -	_default = ::new RenderStyle(true);
  -
  -    box = _default->box;
  -    visual = _default->visual;
  -    background = _default->background;
  -    surround = _default->surround;
  -    css3NonInheritedData = _default->css3NonInheritedData;
  -    css3InheritedData = _default->css3InheritedData;
  -    
  -    inherited = _default->inherited;
  +    if (!defaultStyle)
  +        defaultStyle = ::new RenderStyle(true);
  +    return defaultStyle;
  +}
   
  +RenderStyle::RenderStyle()
  +    : box(initDefaultStyle()->box)
  +    , visual(defaultStyle->visual)
  +    , background(defaultStyle->background)
  +    , surround(defaultStyle->surround)
  +    , css3NonInheritedData(defaultStyle->css3NonInheritedData)
  +    , css3InheritedData(defaultStyle->css3InheritedData)
  +    , inherited(defaultStyle->inherited)
  +    , pseudoStyle(0)
  +    , content(0)
  +    , m_pseudoState(PseudoUnknown)
  +    , m_affectedByAttributeSelectors(false)
  +    , m_ref(0)
   #if SVG_SUPPORT
  -    m_svgStyle = _default->m_svgStyle;
  +    , m_svgStyle(defaultStyle->m_svgStyle)
   #endif
   
  -    setBitDefaults();
  -
  -    pseudoStyle = 0;
  -    content = 0;
  +{
  +    setBitDefaults(); // Would it be faster to copy this from the default style?
   }
   
   RenderStyle::RenderStyle(bool)
  @@ -870,14 +872,11 @@
   }
   
   
  -RenderStyle* RenderStyle::_default = 0;
   //int RenderStyle::counter = 0;
   //int SharedData::counter = 0;
   
   void RenderStyle::cleanup()
   {
  -    delete _default;
  -    _default = 0;
   //    counter = 0;
   //    SharedData::counter = 0;
   }
  @@ -1128,3 +1127,5 @@
       }
       return noneList;
   }
  +
  +}
  
  
  
  1.101     +0 -3      WebCore/khtml/rendering/render_style.h
  
  Index: render_style.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_style.h,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- render_style.h	6 Dec 2005 01:53:13 -0000	1.100
  +++ render_style.h	22 Dec 2005 16:46:39 -0000	1.101
  @@ -1032,9 +1032,6 @@
       
   // !END SYNC!
   
  -// static default style
  -    static RenderStyle* _default;
  -
   protected:
       void setBitDefaults()
       {
  
  
  



More information about the webkit-changes mailing list