Opened 15 years ago
Last modified 15 years ago
#7067 confirmed Bug
about getIndex method performance — at Initial Version
| Reported by: | campaign | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Performance | Version: | |
| Keywords: | HasPatch | Cc: |
Description
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;
},
