getBoundaryInformation this method is very slowly
For example, a child node of parent 738
more 100ms cost each time in getBoundaryInformation
my code
use children property / dichotomy
only 4ms each time
For example, a child node of parent 738
more 100ms cost each time in getBoundaryInformation
my code
use children property / dichotomy
only 4ms each time
var getBoundaryInformation = function( range, start ) { var getIndex = function( n ) { var parent = n.parentNode, currentIndex = -1, node; if ( parent ) { node = parent.firstChild; while ( node ) { currentIndex++; if ( node === n )break; node = node.nextSibling; } } return currentIndex; }; range = range.duplicate(); range.collapse( start ); var parent = range.parentElement(); //如果节点里没有子节点,直接退出 if(!parent.hasChildNodes()){ return {container:parent,offset:0}; } var siblings = parent.children, child, testRange = range.duplicate(), startIndex = 0,endIndex = siblings.length - 1,index=-1, distance; while (startIndex <= endIndex) { index = Math.floor((startIndex + endIndex) / 2); child = siblings[index]; testRange.moveToElementText(child); var position = testRange.compareEndPoints( 'StartToStart', range ); if (position > 0) { endIndex = index - 1; } else if (position < 0) { startIndex = index + 1; } else { return {container:parent,offset:getIndex(child)} } } if(index==-1){ testRange.moveToElementText(parent); testRange.setEndPoint('StartToStart',range); distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length; siblings = parent.childNodes; if(!distance){ child = siblings[siblings.length-1]; return {container:child,offset:child.nodeValue.length}; } var i = siblings.length ; while ( distance > 0 ) distance -= siblings[ --i ].nodeValue.length; return {container:siblings[i],offset:-distance} } if(position>0){ testRange.collapse(); testRange.setEndPoint('StartToStart',range); distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length; if(!distance){ return {container:parent,offset:getIndex(child)-1} } while(distance>0){ child = child.previousSibling; try{ distance -= child.nodeValue.length; }catch(e){ return {container:parent,offset:getIndex(child)} } } return {container:child,offset:-distance} }else{ testRange.collapse(false); testRange.setEndPoint('EndToStart' , range); distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length; if(!distance){ return {container:parent,offset:getIndex(child)+1} } while(distance>0){ child = child.nextSibling; try{ distance -= child.nodeValue.length; }catch(e){ return {container:parent,offset:getIndex(child)} } } return {container:child,offset:child.nodeValue.length-distance} } };
Re: getBoundaryInformation this method is very slowly
Please, post this at the dev site
Edit:
I've filed http://dev.ckeditor.com/ticket/6837
Re: getBoundaryInformation this method is very slowly
This still appears to be an issue in 3.6.2. From www.ckeditor.com/demo enable scayt, clear everything out, then rapidly type. On my box the CPU can spike as high as 40%. If running locally against _source the IE8 profiler points out getBoundaryInformation as the function where most of the time is spent. Has anyone attempted to resolve this on their own? This can be problematic on Citrix boxes where several users have to coexist and live w/CPU limits/process.