Solved

IHTMLTxtRange MoveStart very slow?

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Go Fund Me" type plugin 5 66
Application.cfm not found issue 2 64
Level out logo and increase size? 16 51
JS to redirect to prev page 8 47
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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