TRichView.LoadRTF takes a lot of time to execute

General TRichView support forum. Please post your questions here
Post Reply
Lars Boshold
Posts: 2
Joined: Wed Nov 27, 2024 12:14 pm

TRichView.LoadRTF takes a lot of time to execute

Post by Lars Boshold »

We are facing a situation where calling TRichView.LoadRTF takes a lot of time (several minutes), this does not occur with every rtf-file but only with certain ones, these files are not especially large.
When debugging you can see the two routines TCustomRVData.MassSimpleConcate and TCustomRVData.SimpleConcateSubitems are called a massive lot of times, several orders of magnitude more often than with files which do not show this behaviour. (>1 billion vs. 2-3 digit number of times)

This effect can be reproduced with demo "TRichView\Demos\DelphiUnicode\OfficeConverters" and attached file "Problem_Demo.rtf".

Is the rtf file corrupt in any way or is there a flaw in the RichView-code?

Regards,
Lars
Attachments
Problem_Demo.rtf
(113.47 KiB) Downloaded 20 times
Sergey Tkachenko
Site Admin
Posts: 17857
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichView.LoadRTF takes a lot of time to execute

Post by Sergey Tkachenko »

This is a TRichView bug.
It appears that SimpleConcateSubitems processes each item in table cells twice (when calling MassSimpleConcate, and directly in SimpleConcateSubitems). As a result, the number of calls grows exponentially depending on the table nesting level.
When table nesting level is not high, it's not a problem. But in your document, the maximum count tables nested in each other is 28!

The problem was not found before because this level of nesting is very untypical for Word documents.

Quick fix.
In CRVData.pas, change procedure TCustomRVData.SimpleConcateSubitems to:

Code: Select all

procedure TCustomRVData.SimpleConcateSubitems(ItemNo: Integer);
var
  StoreSub:  TRVStoreSubRVData;
  SubRVData: TCustomRVData;
  item:      TCustomRVItemInfo;
begin
  item := GetItem(ItemNo);
  StoreSub := nil;
  SubRVData := TCustomRVData(item.GetSubRVData(StoreSub, rvdFirst));
  while SubRVData <> nil do
  begin
    SubRVData.MassSimpleConcate(0, SubRVData.ItemCount - 1);
    SubRVData := TCustomRVData(item.GetSubRVData(StoreSub, rvdNext));
  end;
  StoreSub.Free;
end;
Lars Boshold
Posts: 2
Joined: Wed Nov 27, 2024 12:14 pm

Re: TRichView.LoadRTF takes a lot of time to execute

Post by Lars Boshold »

Thanks, your fix solved the problem
Post Reply