Speed up xmleql performance

This commit is contained in:
Bart van den Eijnden
2015-03-26 16:03:28 +01:00
parent 2c04e4c071
commit 616a0b161e
2 changed files with 56 additions and 65 deletions
-1
View File
@@ -977,7 +977,6 @@ describe('ol.format.GML3', function() {
});
it('writes back features as GML', function() {
this.timeout(4000);
var serialized = gmlFormat.writeFeaturesNode(features);
expect(serialized).to.xmleql(ol.xml.parse(text));
});
+43 -51
View File
@@ -116,36 +116,25 @@
function assertElementNodesEqual(node1, node2, options, errors) {
var testPrefix = (options && options.prefix === true);
try {
expect(node1.nodeType).to.equal(node2.nodeType);
} catch(e) {
if (node1.nodeType !== node2.nodeType) {
errors.push('nodeType test failed for: ' + node1.nodeName + ' | ' +
node2.nodeName + ' | ' + e.message);
node2.nodeName);
}
if (testPrefix) {
try {
expect(node1.nodeName).to.equal(node2.nodeName);
} catch(e) {
if (node1.nodeName !== node2.nodeName) {
errors.push('nodeName test failed for: ' + node1.nodeName + ' | ' +
node2.nodeName + ' | ' + e.message);
node2.nodeName);
}
} else {
try {
expect(node1.nodeName.split(':').pop()).to.equal(
node2.nodeName.split(':').pop());
} catch(e) {
} else if (node1.nodeName.split(':').pop() !==
node2.nodeName.split(':').pop()) {
errors.push('nodeName test failed for: ' + node1.nodeName + ' | ' +
node2.nodeName + ' | ' + e.message);
}
node2.nodeName);
}
// for text nodes compare value
if (node1.nodeType === 3) {
try {
// TODO should we make this optional?
expect(node1.nodeValue.replace(/\s/g, '')).to.equal(
node2.nodeValue.replace(/\s/g, ''));
} catch(e) {
errors.push('nodeValue test failed | ' + e.message);
if (node1.nodeValue.replace(/\s/g, '') !==
node2.nodeValue.replace(/\s/g, '')) {
errors.push('nodeValue test failed');
}
}
// for element type nodes compare namespace, attributes, and children
@@ -153,20 +142,14 @@
// test namespace alias and uri
if (node1.prefix || node2.prefix) {
if (testPrefix) {
try {
expect(node1.prefix).to.equal(node2.prefix);
} catch(e) {
errors.push('Prefix test failed for: ' + node1.nodeName + ' | ' +
e.message);
if (node1.prefix !== node2.prefix) {
errors.push('Prefix test failed for: ' + node1.nodeName);
}
}
}
if (node1.namespaceURI || node2.namespaceURI) {
try {
expect(node1.namespaceURI).to.equal(node2.namespaceURI);
} catch(e) {
errors.push('namespaceURI test failed for: ' + node1.nodeName +
' | ' + e.message);
if (node1.namespaceURI !== node2.namespaceURI) {
errors.push('namespaceURI test failed for: ' + node1.nodeName);
}
}
// compare attributes - disregard xmlns given namespace handling above
@@ -200,11 +183,8 @@
}
}
}
try {
expect(node1AttrLen).to.equal(node2AttrLen);
} catch(e) {
errors.push('Number of attributes test failed for: ' + node1.nodeName +
' | ' + e.message);
if (node1AttrLen !== node2AttrLen) {
errors.push('Number of attributes test failed for: ' + node1.nodeName);
}
var gv, ev;
for (var name in node1Attr) {
@@ -213,32 +193,44 @@
' expected for element ' + node1.nodeName);
}
// test attribute namespace
try {
// we do not care about the difference between an empty string and
// null for namespaceURI some tests will fail in IE9 otherwise
// see also
// http://msdn.microsoft.com/en-us/library/ff460650(v=vs.85).aspx
expect(node1Attr[name].namespaceURI || null).to.be(
node2Attr[name].namespaceURI || null);
} catch(e) {
if ((node1Attr[name].namespaceURI || null) !==
(node2Attr[name].namespaceURI || null)) {
errors.push('namespaceURI attribute test failed for: ' +
node1.nodeName + ' | ' + e.message);
node1.nodeName);
}
try {
expect(node1Attr[name].value).to.equal(node2Attr[name].value);
} catch(e) {
errors.push('Attribute value test failed for: ' + node1.nodeName +
' | ' + e.message);
if (node1Attr[name].value !== node2Attr[name].value) {
errors.push('Attribute value test failed for: ' + node1.nodeName);
}
}
// compare children
var node1ChildNodes = getChildNodes(node1, options);
var node2ChildNodes = getChildNodes(node2, options);
try {
expect(node1ChildNodes.length).to.equal(node2ChildNodes.length);
} catch(e) {
errors.push('Number of childNodes test failed for: ' + node1.nodeName +
' | ' + e.message);
if (node1ChildNodes.length !== node2ChildNodes.length) {
// check if all child nodes are text, they could be split up in
// 4096 chunks
// if so, ignore the childnode count error
var allText = true;
var c, cc;
for (c = 0, cc = node1ChildNodes.length; c < cc; ++c) {
if (node1ChildNodes[c].nodeType !== 3) {
allText = false;
break;
}
}
for (c = 0, cc = node2ChildNodes.length; c < cc; ++c) {
if (node2ChildNodes[c].nodeType !== 3) {
allText = false;
break;
}
}
if (!allText) {
errors.push('Number of childNodes test failed for: ' +
node1.nodeName);
}
}
// only compare if they are equal
if (node1ChildNodes.length === node2ChildNodes.length) {