[webkit-changes] cvs commit: WebCore/ksvg2/svg
SVGTransformableImpl.cpp
Maciej
mjs at opensource.apple.com
Tue Dec 20 12:12:50 PST 2005
mjs 05/12/20 12:12:50
Modified: . ChangeLog
kjs identifier.cpp identifier.h property_map.cpp
ustring.cpp
kxmlcore PassRefPtr.h RefPtr.h
. ChangeLog
khtml/xml dom_elementimpl.cpp
ksvg2/svg SVGTransformableImpl.cpp
Log:
JavaScriptCore:
Reviewed by Darin.
- fixed a leak in the assignment operator from PassRefPtr to RefPtr
* kxmlcore/RefPtr.h:
(KXMLCore::RefPtr::operator=):
- fix problem with PassRefPtr that darin spotted - it lacked a copy constructor
and therefore was using the default one, which can lead to excess derefs
I fixed this by adding a copy constructor from non-const
reference, and by adding a template pass() function that you have
to use when raw pointer or RefPtr are passed where PassRefPtr is
expected.
* kjs/identifier.cpp:
(KJS::Identifier::add): Changed to have PassRefPtr return type and
pass() the results.
* kjs/identifier.h:
* kjs/property_map.cpp:
(KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): Use pass()
where required.
* kjs/ustring.cpp:
(KJS::UString::UString): Use pass() as needed.
(KJS::UString::append): ditto
(KJS::UString::substr): ditto
* kjs/ustring.h:
(KJS::UString::UString): Use initializer instead of assignment
* kxmlcore/PassRefPtr.h:
(KXMLCore::PassRefPtr::PassRefPtr): Added copy constructor
(KXMLCore::pass): new template function to make it convenient to pass
a PassRefPtr
WebCore:
Reviewed by Darin.
- change an assignment to a contructor declaration to build with PassRefPtr
leak fix changes
* ksvg2/svg/SVGTransformableImpl.cpp:
(SVGTransformableImpl::parseTransformAttribute):
Revision Changes Path
1.915 +35 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.914
retrieving revision 1.915
diff -u -r1.914 -r1.915
--- ChangeLog 20 Dec 2005 18:34:29 -0000 1.914
+++ ChangeLog 20 Dec 2005 20:12:44 -0000 1.915
@@ -1,3 +1,38 @@
+2005-12-19 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by Darin.
+
+ - fixed a leak in the assignment operator from PassRefPtr to RefPtr
+
+ * kxmlcore/RefPtr.h:
+ (KXMLCore::RefPtr::operator=):
+
+ - fix problem with PassRefPtr that darin spotted - it lacked a copy constructor
+ and therefore was using the default one, which can lead to excess derefs
+
+ I fixed this by adding a copy constructor from non-const
+ reference, and by adding a template pass() function that you have
+ to use when raw pointer or RefPtr are passed where PassRefPtr is
+ expected.
+
+ * kjs/identifier.cpp:
+ (KJS::Identifier::add): Changed to have PassRefPtr return type and
+ pass() the results.
+ * kjs/identifier.h:
+ * kjs/property_map.cpp:
+ (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): Use pass()
+ where required.
+ * kjs/ustring.cpp:
+ (KJS::UString::UString): Use pass() as needed.
+ (KJS::UString::append): ditto
+ (KJS::UString::substr): ditto
+ * kjs/ustring.h:
+ (KJS::UString::UString): Use initializer instead of assignment
+ * kxmlcore/PassRefPtr.h:
+ (KXMLCore::PassRefPtr::PassRefPtr): Added copy constructor
+ (KXMLCore::pass): new template function to make it convenient to pass
+ a PassRefPtr
+
2005-12-19 Geoffrey Garen <ggaren at apple.com>
Reviewed by Maciej.
1.25 +11 -11 JavaScriptCore/kjs/identifier.cpp
Index: identifier.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/identifier.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- identifier.cpp 19 Dec 2005 10:38:07 -0000 1.24
+++ identifier.cpp 20 Dec 2005 20:12:47 -0000 1.25
@@ -123,15 +123,15 @@
return r;
}
-UString::Rep *Identifier::add(const char *c)
+PassRefPtr<UString::Rep> Identifier::add(const char *c)
{
if (!c)
- return &UString::Rep::null;
+ return pass(&UString::Rep::null);
int length = strlen(c);
if (length == 0)
- return &UString::Rep::empty;
+ return pass(&UString::Rep::empty);
- return *identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first;
+ return pass(*identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first);
}
struct UCharBuffer {
@@ -163,27 +163,27 @@
return r;
}
-UString::Rep *Identifier::add(const UChar *s, int length)
+PassRefPtr<UString::Rep> Identifier::add(const UChar *s, int length)
{
if (length == 0)
- return &UString::Rep::empty;
+ return pass(&UString::Rep::empty);
UCharBuffer buf = {s, length};
- return *identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first;
+ return pass(*identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first);
}
-UString::Rep *Identifier::add(UString::Rep *r)
+PassRefPtr<UString::Rep> Identifier::add(UString::Rep *r)
{
if (r->isIdentifier)
- return r;
+ return pass(r);
if (r->len == 0)
- return &UString::Rep::empty;
+ return pass(&UString::Rep::empty);
UString::Rep *result = *identifierTable().insert(r).first;
if (result == r)
r->isIdentifier = true;
- return result;
+ return pass(result);
}
void Identifier::remove(UString::Rep *r)
1.22 +3 -3 JavaScriptCore/kjs/identifier.h
Index: identifier.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/identifier.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- identifier.h 19 Dec 2005 10:38:07 -0000 1.21
+++ identifier.h 20 Dec 2005 20:12:47 -0000 1.22
@@ -77,9 +77,9 @@
static bool equal(const Identifier &a, const char *b)
{ return equal(a._ustring.rep(), b); }
- static UString::Rep *add(const char *);
- static UString::Rep *add(const UChar *, int length);
- static UString::Rep *add(UString::Rep *);
+ static PassRefPtr<UString::Rep> add(const char *);
+ static PassRefPtr<UString::Rep> add(const UChar *, int length);
+ static PassRefPtr<UString::Rep> add(UString::Rep *);
};
#if !KJS_IDENTIFIER_HIDE_GLOBALS
1.55 +4 -4 JavaScriptCore/kjs/property_map.cpp
Index: property_map.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/property_map.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- property_map.cpp 11 Dec 2005 02:05:47 -0000 1.54
+++ property_map.cpp 20 Dec 2005 20:12:47 -0000 1.55
@@ -614,11 +614,11 @@
#if USE_SINGLE_ENTRY
UString::Rep *key = _singleEntry.key;
if (key) {
- UString k(key);
+ UString k(pass(key));
bool fitsInUInt32;
k.toUInt32(&fitsInUInt32);
if (fitsInUInt32)
- list.append(Reference(base, Identifier(key)));
+ list.append(Reference(base, Identifier(pass(key))));
}
#endif
return;
@@ -629,11 +629,11 @@
for (int i = 0; i != size; ++i) {
UString::Rep *key = entries[i].key;
if (key && key != &UString::Rep::null) {
- UString k(key);
+ UString k(pass(key));
bool fitsInUInt32;
k.toUInt32(&fitsInUInt32);
if (fitsInUInt32)
- list.append(Reference(base, Identifier(key)));
+ list.append(Reference(base, Identifier(pass(key))));
}
}
}
1.66 +8 -6 JavaScriptCore/kjs/ustring.cpp
Index: ustring.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/ustring.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- ustring.cpp 16 Dec 2005 22:48:19 -0000 1.65
+++ ustring.cpp 20 Dec 2005 20:12:47 -0000 1.66
@@ -199,6 +199,7 @@
r->capacity = l;
r->usedPreCapacity = 0;
r->preCapacity = 0;
+
// steal the single reference this Rep was created with
return PassRefPtr<Rep>::adopt(r);
}
@@ -228,6 +229,7 @@
r->capacity = 0;
r->usedPreCapacity = 0;
r->preCapacity = 0;
+
// steal the single reference this Rep was created with
return PassRefPtr<Rep>::adopt(r);
}
@@ -457,7 +459,7 @@
UString x(a);
x.expandCapacity(aOffset + length);
memcpy(const_cast<UChar *>(a.data() + aSize), b.data(), bSize * sizeof(UChar));
- m_rep = Rep::create(a.m_rep, 0, length);
+ m_rep = Rep::create(pass(a.m_rep), 0, length);
} else if (-bOffset == b.usedPreCapacity() && 4 * bSize >= aSize) {
// - b reaches the beginning of its buffer so it qualifies for shared prepend
// - also, it's at least a quarter the length of a - prepending to a much shorter
@@ -465,7 +467,7 @@
UString y(b);
y.expandPreCapacity(-bOffset + aSize);
memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar));
- m_rep = Rep::create(b.m_rep, -aSize, length);
+ m_rep = Rep::create(pass(b.m_rep), -aSize, length);
} else {
// a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string
int newCapacity = expandedSize(length, 0);
@@ -683,7 +685,7 @@
// this reaches the end of the buffer - extend it
expandCapacity(thisOffset + length);
memcpy(const_cast<UChar *>(data() + thisSize), t.data(), tSize * sizeof(UChar));
- m_rep = Rep::create(m_rep, 0, length);
+ m_rep = Rep::create(pass(m_rep), 0, length);
} else {
// this is shared with someone using more capacity, gotta make a whole new string
int newCapacity = expandedSize(length, 0);
@@ -724,7 +726,7 @@
UChar *d = const_cast<UChar *>(data());
for (int i = 0; i < tSize; ++i)
d[thisSize+i] = t[i];
- m_rep = Rep::create(m_rep, 0, length);
+ m_rep = Rep::create(pass(m_rep), 0, length);
} else {
// this is shared with someone using more capacity, gotta make a whole new string
int newCapacity = expandedSize(length, 0);
@@ -764,7 +766,7 @@
expandCapacity(thisOffset + length + 1);
UChar *d = const_cast<UChar *>(data());
d[length] = c;
- m_rep = Rep::create(m_rep, 0, length + 1);
+ m_rep = Rep::create(pass(m_rep), 0, length + 1);
} else {
// this is shared with someone using more capacity, gotta make a whole new string
int newCapacity = expandedSize((length + 1), 0);
@@ -1120,7 +1122,7 @@
if (pos == 0 && len == s)
return *this;
- return UString(Rep::create(m_rep, pos, len));
+ return UString(Rep::create(pass(m_rep), pos, len));
}
void UString::copyForWriting()
1.5 +13 -1 JavaScriptCore/kxmlcore/PassRefPtr.h
Index: PassRefPtr.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kxmlcore/PassRefPtr.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PassRefPtr.h 19 Dec 2005 20:48:23 -0000 1.4
+++ PassRefPtr.h 20 Dec 2005 20:12:48 -0000 1.5
@@ -44,6 +44,7 @@
PassRefPtr() : m_ptr(0) {}
PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
+ PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {}
~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
@@ -83,7 +84,7 @@
m_ptr = ref.m_ptr;
return *this;
}
-
+
template<typename U>
operator PassRefPtr_Ref<U>()
{
@@ -190,10 +191,21 @@
return PassRefPtr<T>::adopt(const_cast<T *>(p.release()));
}
+ template <typename T> inline PassRefPtr<T> pass(T *ptr)
+ {
+ return PassRefPtr<T>(ptr);
+ }
+
+ template <typename T> inline PassRefPtr<T> pass(const RefPtr<T>& ptr)
+ {
+ return PassRefPtr<T>(ptr);
+ }
+
} // namespace KXMLCore
using KXMLCore::PassRefPtr;
using KXMLCore::static_pointer_cast;
using KXMLCore::const_pointer_cast;
+using KXMLCore::pass;
#endif // KXMLCORE_PASS_REF_PTR_H
1.7 +1 -4 JavaScriptCore/kxmlcore/RefPtr.h
Index: RefPtr.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kxmlcore/RefPtr.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RefPtr.h 19 Dec 2005 20:48:23 -0000 1.6
+++ RefPtr.h 20 Dec 2005 20:12:48 -0000 1.7
@@ -90,12 +90,9 @@
template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
{
- T *optr = o.release();
- if (optr)
- optr->ref();
if (T *ptr = m_ptr)
ptr->deref();
- m_ptr = optr;
+ m_ptr = o.release();
return *this;
}
1.11 +10 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ChangeLog 20 Dec 2005 17:05:50 -0000 1.10
+++ ChangeLog 20 Dec 2005 20:12:49 -0000 1.11
@@ -1,3 +1,13 @@
+2005-12-20 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by Darin.
+
+ - change an assignment to a contructor declaration to build with PassRefPtr
+ leak fix changes
+
+ * ksvg2/svg/SVGTransformableImpl.cpp:
+ (SVGTransformableImpl::parseTransformAttribute):
+
2005-12-20 Geoffrey Garen <ggaren at apple.com>
Reviewed by John.
1.100 +0 -1 WebCore/khtml/xml/dom_elementimpl.cpp
Index: dom_elementimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_elementimpl.cpp,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -r1.99 -r1.100
--- dom_elementimpl.cpp 19 Dec 2005 20:41:46 -0000 1.99
+++ dom_elementimpl.cpp 20 Dec 2005 20:12:49 -0000 1.100
@@ -1397,7 +1397,6 @@
void StyledElementImpl::createAttributeMap() const
{
namedAttrMap = new NamedMappedAttrMapImpl(const_cast<StyledElementImpl*>(this));
- namedAttrMap->ref();
}
CSSMutableStyleDeclarationImpl* StyledElementImpl::getInlineStyleDecl()
1.10 +1 -1 WebCore/ksvg2/svg/SVGTransformableImpl.cpp
Index: SVGTransformableImpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/ksvg2/svg/SVGTransformableImpl.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SVGTransformableImpl.cpp 13 Dec 2005 21:25:13 -0000 1.9
+++ SVGTransformableImpl.cpp 20 Dec 2005 20:12:50 -0000 1.10
@@ -91,7 +91,7 @@
subtransform[0] = subtransform[0].right(subtransform[0].length() - 1);
}
- PassRefPtr<SVGTransformImpl> t = new SVGTransformImpl();
+ PassRefPtr<SVGTransformImpl> t(new SVGTransformImpl());
if(subtransform[0] == QString::fromLatin1("rotate"))
{
More information about the webkit-changes
mailing list