Solved

IHTMLTxtRange MoveStart very slow?

Posted on 2010-08-23
2
1,010 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
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.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now