1、CnWizUtils.pas内有放多取得OTA 接口的函数,这些函数在短短的10分钟内总共调用有上百万次,经检测存在以下“问题”,
举一个例子:原函数:
function CnOtaGetEditBuffer: IOTAEditBuffer;
var
iEditorServices: IOTAEditorServices;
begin
Result := nil; //:=nil放在上面要占用该函数10-40%的时间,可能是接口取空值与实列取空值处理机制不一样,
QuerySvcs(BorlandIDEServices, IOTAEditorServices, iEditorServices);
if iEditorServices <> nil then
Result := iEditorServices.GetTopBuffer;
end;
建议改成如下表达:
function CnOtaGetEditBuffer: IOTAEditBuffer;
var
iEditorServices: IOTAEditorServices;
begin
QuerySvcs(BorlandIDEServices, IOTAEditorServices, iEditorServices);
if iEditorServices <> nil then
begin
Result := iEditorServices.GetTopBuffer;
Exit;//取得后直接退出,
end;
Result := nil;//没取得时再用:=nil,放在这里,不占用时间
end;
附件是我改好的CnWizUtils.pas
修改后测不出这些函数调用时间
第3个问题有没有办法解决?我试了将AddApplicationIdleNotifier参数类型改成TIdleEvent,
原型为:TIdleEvent = procedure (Sender: TObject; var Done: Boolean) of object;
delphi可能取出Done值为True,如果能在Done做做文章就好了,
下面是简单的调试方法,类似于cndebug,不过比cndebug方便,
安装codesite 4,
将下例单元加到delphi路径下
unit csos;
interface
uses
SysUtils,CodeSiteLogging;
function rc4:TCodeSiteObject;
var
Frc4:TCodeSiteObject;
implementation
function rc4:TCodeSiteObject;
begin
if not Assigned(Frc4) then
Frc4:=TCodeSiteObject.Create(nil);
Result:=Frc4;
end;
initialization
finalization
if Assigned(Frc4) then
FreeAndNil(Frc4);
end.
在CnEditControlWrapper.pas引用csos
在TCnEditControlWrapper.OnIdle内加一行rc4.sendvariant('Done',Done);你会发现,当delphi空闲时,OnIdle一直重复计算,D2007比D2006更快,不过D2006每秒钟也有好几次,而且每算一次都会调用Result.LineCount := Editor.EditView.Buffer.GetLinesInBuffer,这句话很占用时间;,如果能想到办法,让OnIdle只计算一次就好了,Author:
niaoge Time: 2007-6-14 11:14