Solved

IHTMLTxtRange MoveStart very slow?

Posted on 2010-08-23
2
1,023 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Part One of the two-part Q&A series with MalwareTech.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

623 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