[Qt-qml] memory use in javascript
Malte Marquarding
malte at marquarding.com
Thu Mar 24 06:15:36 CET 2011
Hi,
I am using the following javascript function to decode xml data (for an
XmlModel). This seems to allocate a lot of memory.
As per code comment I managed to reduce it by a lot already.
Is there anything obviously wrong?
function lzdecode(instr) {
var ecPos = instr.indexOf("<")-1
var eC = instr.charAt(ecPos);
var data = new String(instr.slice(ecPos+1));
var outstr = new String();
var p = 0;
var l = 0;
for (var n=0; n<data.length; n++) {
// this code consume a lot of memory
if (data.charAt(n) == eC) {
p = data.charCodeAt(n+1)*114 + data.charCodeAt(n+2) - 1610;
l = data.charCodeAt(n+3)-14;
// cast to string otherwise we allocate heaps of memory???!
outstr += String(outstr.substr(-p,l))
n += 3;
} else {
// This doesn't
outstr += data.charAt(n);
}
}
return outstr;
Cheers,
Malte.
More information about the Qt-qml
mailing list