Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IHTMLTxtRange MoveStart very slow?

Posted on 2010-08-23
2
Medium Priority
?
1,029 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

876 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