I was just looking at the latest DynAPI, and found a couple of things I
thought could be optimized, mostly in setHTML.

setHTML has been split into _setHTML for different browsers which is called
from the setHTML function, I'll paste in the code and add some comments...

if (is.ns4) {
        DynLayer.prototype._setHTML=function(html) {
                sTmp=(this.w==null)?'<NOBR>'+this.html+'</NOBR>':this.html
                this.doc.open()
                this.doc.write(sTmp)
                this.doc.close()
                for (var i in this.doc.images) this.doc.images[i].lyrobj=this;
                for (i=0;i<this.doc.links.length;i++)
this.doc.links[i].lyrobj=this;
        }
} else if (is.ie) {
        DynLayer.prototype._setHTML=function(html) { for (i in
this.elm.all.tags("img")) this.elm.all.tags("img")[i].lyrobj=this }

// Because of changes that Jordi made to event's ages ago I beleive the
above line is not needed. Is that correct?

} else

        DynLayer.prototype._setHTML=function(html) {;
                sTmp=(this.w==null)?'<NOBR>'+this.html+'</NOBR>':this.html;
                while (this.elm.hasChildNodes())
this.elm.removeChild(this.elm.firstChild);
                var r=this.elm.ownerDocument.createRange();
                r.selectNodeContents(this.elm);
                r.collapse(true);
                var df=r.createContextualFragment(sTmp);
                this.elm.appendChild(df);
                for (i in this.doc.images) this.doc.images[i].lyrobj=this.elm;

                // I don't think the above line is needed either, the event method 
should
find the parent layer for any image.
        }
}
DynLayer.prototype.setHTML=function(html,noevt) {
        this.html=html?html:'';
        if (this.platform=='mac') this.html+='\n';
        if (this.css==null) return;
        if (noevt!=false) this.invokeEvent("beforeload");
        this.elm.innerHTML=html;

        /* The above line is the one I have a real objection to - because NS6
supports innerHTML, and the code in the NS6 version of _setHTML is a DOM
method of doing innerHTML, the html is being set twice. NS4 doesn't support
the innerHTML command, so setting the innerHTML on the elm is making another
copy of the .html which is (probably) redundant. */

        this._setHTML(html);
        if (noevt!=false) this.invokeEvent("load");
}

Just some suggestions. If I get a chance I'll have a go at making these
changes and see if anything breaks.

Something else I read on another list that speeds things up, is making your
for loops run backwards, for example, instead of doing this:

for(var i=0;i<obj.length;i++) {...}

do it like this:

for(var i=obj.length-1;i>-1;i--) {...}

it's faster because obj.length is only evaluated once, rather than many
times. of course if obj.length changes while the loop is running it could
get you into trouble ;-)

Cheers,

Cameron.


_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev

Reply via email to