[webkit-changes] cvs commit: WebCore/khtml/xsl
xslt_processorimpl.cpp xslt_processorimpl.h
Maciej
mjs at opensource.apple.com
Thu Dec 22 19:57:26 PST 2005
mjs 05/12/22 19:57:25
Modified: . ChangeLog
khtml/xml dom_stringimpl.cpp dom_stringimpl.h
khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h
Log:
Reviewed by Eric.
- made RefPtr<DOMStringImpl> usable as a hashtable key/value
- changed XSLTProcessorImpl to make use of this instead of a QDict.
- partially fixed broken param handling for xslt
See LayoutTests for updated test case.
* khtml/xml/dom_stringimpl.cpp:
* khtml/xml/dom_stringimpl.h:
(KXMLCore::): Set things up so you can use RefPtr<DOMStringImpl> as
a hashtable key (should already be usable as a value).
* khtml/xsl/xslt_processorimpl.cpp:
(DOM::xsltParamArrayFromParameterMap): Updated to use a HashMap of RefPtrs instead
of QDict. Also, fixed bugs that would have kept this from ever working at all.
(DOM::XSLTProcessorImpl::transformToString): ditto
(DOM::XSLTProcessorImpl::setParameter): ditto
(DOM::XSLTProcessorImpl::getParameter): ditto
(DOM::XSLTProcessorImpl::removeParameter): ditto
* khtml/xsl/xslt_processorimpl.h:
Revision Changes Path
1.31 +23 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- ChangeLog 23 Dec 2005 01:52:39 -0000 1.30
+++ ChangeLog 23 Dec 2005 03:57:24 -0000 1.31
@@ -1,3 +1,26 @@
+2005-12-22 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by Eric.
+
+ - made RefPtr<DOMStringImpl> usable as a hashtable key/value
+ - changed XSLTProcessorImpl to make use of this instead of a QDict.
+ - partially fixed broken param handling for xslt
+
+ See LayoutTests for updated test case.
+
+ * khtml/xml/dom_stringimpl.cpp:
+ * khtml/xml/dom_stringimpl.h:
+ (KXMLCore::): Set things up so you can use RefPtr<DOMStringImpl> as
+ a hashtable key (should already be usable as a value).
+ * khtml/xsl/xslt_processorimpl.cpp:
+ (DOM::xsltParamArrayFromParameterMap): Updated to use a HashMap of RefPtrs instead
+ of QDict. Also, fixed bugs that would have kept this from ever working at all.
+ (DOM::XSLTProcessorImpl::transformToString): ditto
+ (DOM::XSLTProcessorImpl::setParameter): ditto
+ (DOM::XSLTProcessorImpl::getParameter): ditto
+ (DOM::XSLTProcessorImpl::removeParameter): ditto
+ * khtml/xsl/xslt_processorimpl.h:
+
2005-12-21 Maciej Stachowiak <mjs at apple.com>
Reviewed by Darin.
1.34 +6 -0 WebCore/khtml/xml/dom_stringimpl.cpp
Index: dom_stringimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_stringimpl.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- dom_stringimpl.cpp 21 Nov 2005 04:01:58 -0000 1.33
+++ dom_stringimpl.cpp 23 Dec 2005 03:57:25 -0000 1.34
@@ -583,3 +583,9 @@
}
} // namespace DOM
+
+namespace KXMLCore {
+
+const RefPtr<DOM::DOMStringImpl> HashTraits<RefPtr<DOM::DOMStringImpl> >::_deleted = new DOM::DOMStringImpl(reinterpret_cast<char *>(0), 0);
+
+}
1.19 +27 -0 WebCore/khtml/xml/dom_stringimpl.h
Index: dom_stringimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_stringimpl.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- dom_stringimpl.h 21 Nov 2005 04:01:59 -0000 1.18
+++ dom_stringimpl.h 23 Dec 2005 03:57:25 -0000 1.19
@@ -26,6 +26,7 @@
#include "misc/khtmllayout.h"
#include "misc/shared.h"
+#include <kxmlcore/RefPtr.h>
#define QT_ALLOC_QCHAR_VEC(N) static_cast<QChar*>(fastMalloc(sizeof(QChar)*(N)))
#define QT_DELETE_QCHAR_VEC(P) fastFree(P)
@@ -194,6 +195,32 @@
}
};
+ template<> struct DefaultHash<RefPtr<DOM::DOMStringImpl> > {
+ static unsigned hash(const RefPtr<DOM::DOMStringImpl>& key)
+ {
+ return DefaultHash<DOM::DOMStringImpl *>::hash(key.get());
+ }
+
+ static bool equal(const RefPtr<DOM::DOMStringImpl>& a, const RefPtr<DOM::DOMStringImpl>& b)
+ {
+ return DefaultHash<DOM::DOMStringImpl *>::equal(a.get(), b.get());
+ }
+ };
+
+ template <typename T> class HashTraits;
+
+ template<>
+ struct HashTraits<RefPtr<DOM::DOMStringImpl> > {
+ typedef RefPtr<DOM::DOMStringImpl> TraitType;
+
+ static const bool emptyValueIsZero = true;
+ static const bool needsDestruction = true;
+ static const TraitType emptyValue() { return TraitType(); }
+
+ static const TraitType _deleted;
+ static const TraitType& deletedValue() { return _deleted; }
+ };
+
}
using KXMLCore::CaseInsensitiveHash;
1.20 +14 -13 WebCore/khtml/xsl/xslt_processorimpl.cpp
Index: xslt_processorimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- xslt_processorimpl.cpp 20 Dec 2005 08:49:51 -0000 1.19
+++ xslt_processorimpl.cpp 23 Dec 2005 03:57:25 -0000 1.20
@@ -146,17 +146,18 @@
"</html>\n";
}
-static const char **xsltParamArrayFromQDict(QDict<DOMString> parameters)
+static const char **xsltParamArrayFromParameterMap(XSLTProcessorImpl::ParameterMap& parameters)
{
- if (parameters.count())
+ if (parameters.isEmpty())
return 0;
- const char **parameterArray = (const char **)malloc(((parameters.count() * 2) + 1) * sizeof(char *));
- QDictIterator<DOMString> it(parameters);
+ const char **parameterArray = (const char **)malloc(((parameters.size() * 2) + 1) * sizeof(char *));
+
+ XSLTProcessorImpl::ParameterMap::iterator end = parameters.end();
unsigned index = 0;
- for (it.toFirst(); it.current(); ++it) {
- parameterArray[++index] = strdup(it.currentKey().utf8().data());
- parameterArray[++index] = strdup(it.current()->qstring().utf8().data());
+ for (XSLTProcessorImpl::ParameterMap::iterator it = parameters.begin(); it != end; ++it) {
+ parameterArray[index++] = strdup(DOMString(it->first.get()).qstring().utf8().data());
+ parameterArray[index++] = strdup(DOMString(it->second.get()).qstring().utf8().data());
}
parameterArray[index] = 0;
@@ -302,7 +303,7 @@
cachedStylesheet->clearDocuments();
xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode);
- const char **params = xsltParamArrayFromQDict(m_parameters);
+ const char **params = xsltParamArrayFromParameterMap(m_parameters);
xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, params);
freeXsltParamArray(params);
@@ -343,21 +344,21 @@
void XSLTProcessorImpl::setParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName, DOMStringImpl *value)
{
// FIXME: namespace support?
- m_parameters.replace(DOMString(localName).qstring(), new DOMString(value));
+ // should make a QualifiedName here but we'd have to expose the impl
+ m_parameters.set(localName, value);
}
RefPtr<DOMStringImpl> XSLTProcessorImpl::getParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName) const
{
// FIXME: namespace support?
- if (DOMString *value = m_parameters.find(DOMString(localName).qstring()))
- return value->impl();
- return 0;
+ // should make a QualifiedName here but we'd have to expose the impl
+ return m_parameters.get(localName);
}
void XSLTProcessorImpl::removeParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName)
{
// FIXME: namespace support?
- m_parameters.remove(DOMString(localName).qstring());
+ m_parameters.remove(localName);
}
}
1.8 +6 -3 WebCore/khtml/xsl/xslt_processorimpl.h
Index: xslt_processorimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- xslt_processorimpl.h 18 Dec 2005 22:23:27 -0000 1.7
+++ xslt_processorimpl.h 23 Dec 2005 03:57:25 -0000 1.8
@@ -36,6 +36,8 @@
#include "xsl_stylesheetimpl.h"
#include <qstring.h>
+#include <kxmlcore/HashMap.h>
+
namespace DOM {
class NodeImpl;
@@ -45,8 +47,6 @@
class XSLTProcessorImpl : public khtml::Shared<XSLTProcessorImpl>
{
public:
- XSLTProcessorImpl() { m_parameters.setAutoDelete(true); };
-
void setXSLStylesheet(XSLStyleSheetImpl *styleSheet) { m_stylesheet = styleSheet; }
bool transformToString(NodeImpl *source, QString &resultMIMEType, QString &resultString, QString &resultEncoding);
RefPtr<DocumentImpl> createDocumentFromSource(const QString &source, const QString &sourceEncoding, const QString &sourceMIMEType, NodeImpl *sourceNode, KHTMLView *view = 0);
@@ -67,13 +67,16 @@
// Only for libXSLT callbacks
XSLStyleSheetImpl *xslStylesheet() const { return m_stylesheet.get(); }
+ typedef HashMap<RefPtr<DOMStringImpl>, RefPtr<DOMStringImpl> > ParameterMap;
+
private:
// Convert a libxml doc ptr to a KHTML DOM Document
RefPtr<DocumentImpl> documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, DocumentImpl *ownerDocument, bool sourceIsDocument);
RefPtr<XSLStyleSheetImpl> m_stylesheet;
RefPtr<NodeImpl> m_stylesheetRootNode;
- QDict<DOMString> m_parameters;
+
+ ParameterMap m_parameters;
};
}
More information about the webkit-changes
mailing list