Opened 14 years ago
Last modified 14 years ago
#7067 confirmed Bug
about getIndex method performance
Reported by: | campaign | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | Performance | Version: | |
Keywords: | HasPatch | Cc: |
Description (last modified by )
When the getIndex method is called, the getNext will be invoked by getIndex, if an element node contains too many text nodes, the getNext method will be called too many times, that will cause a performance problem. My suggest is using childNodes property, according to my test, using childNodes is nearly two times faster than calling getNext method. Here's my code snippet:
getIndex : function( normalized ) {
var parent = this.getParent(),
currentIndex = -1, node;
if ( parent ) {
for(var i=0,childs=parent.$.childNodes;node=childs[i];i++){
if(node.nodeType == 1 !(normalized && node.previousSibling && node.previousSibling.nodeType == baidu.editor.dom.NODE_TEXT)) currentIndex++;
if(node == this.$)break;
}
} return currentIndex;
},
Change History (2)
comment:1 Changed 14 years ago by
Keywords: | HasPatch added |
---|
comment:2 Changed 14 years ago by
Component: | General → Performance |
---|---|
Description: | modified (diff) |
Status: | new → confirmed |