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
TRichView.LoadRTF takes a lot of time to execute
-
- Posts: 2
- Joined: Wed Nov 27, 2024 12:14 pm
TRichView.LoadRTF takes a lot of time to execute
- Attachments
-
- Problem_Demo.rtf
- (113.47 KiB) Downloaded 20 times
-
- Site Admin
- Posts: 17857
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: TRichView.LoadRTF takes a lot of time to execute
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:
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;
-
- Posts: 2
- Joined: Wed Nov 27, 2024 12:14 pm
Re: TRichView.LoadRTF takes a lot of time to execute
Thanks, your fix solved the problem