Solved

IHTMLTxtRange MoveStart very slow?

Posted on 2010-08-23
2
1,014 Views
Last Modified: 2013-11-25
I'm using IWebBrowser2 to highlight various words  in a page (in a C++ app).     Using IHTMLTxtRange I select my text by doing this:

Range->moveToElementText (pElement);
Range->collapse (true);

Range->moveStart (byChar, nFirstChar, &nActualCount);
Range->moveEnd (byChar, nLenToHighlight, &nActualCount);

It works fine in that my text is highlighted, but it's agonizingly slow.  I just ran it through a profiler and the moveToElementText, collapse, and moveEnd were all very fast (a few tenths of a second for 200+ hits in a debug build).   MoveStart, however, took 36 seconds for the same 200 hits.   So, roughly 100 times slower.

Later in the code we highlight that range using IMarkupServices and IDisplayPointer and IHTMLRenderStyle all of that is very fast (total time for 30-ish lines of COM code for those 200 hits is about .15 seconds).

What in the world makes the call to moveStart so agonizingly slow?  Any suggestions for other ways to insert highlights that will be fast?
0
Comment
Question by:paulf75
2 Comments
 

Author Comment

by:paulf75
ID: 33507114
I believe I've figured it out.  The problem was the way I setup the loop.  moveStart appears to count its way along (rather than moving in one large chunk), so by resetting to the start of the element each time, then moving to where I wanted, it was forcing it to count its way along over and over and over again.

That is, let's say I had 1000 chars and was highlighting every other char.  The way I had it it would have to count over 500,000 chars in the course of the loop (count from 0 to 2, then 0 to 4, then 0 to 6, etc).

I changed it to walk from one highlight to the next (count from 0 to 2, then 2 to 4, then 4 to 6, etc) and it dramatically improved the speed.
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 33713153
paulf75,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question