CnPack Forum


 
Subject: ParsePosInfo函数改成直接从IStream里读
niaoge
灌水司司长
Rank: 6Rank: 6



UID 9910
Digest Posts 0
Credits 438
Posts 143
点点分 438
Reading Access 10
Registered 2007-4-8
Status Offline
Post at 2007-4-25 15:50  Profile | Blog | P.M. 
ParsePosInfo函数改成直接从IStream里读

助手里有一个ParsePosInfo,这个函数,是从当前代码中取出部分代码以便分析结构用,这个函数的性能好坏在大文件时编辑时性能好坏息息相关,我改成直接从IStream中取,
新改成的函数反回值正确,处理过程正确,但我不会测精确的性能,比如花费时间等,暂先放在这里
哪位对 IStream性质比较了解的朋友看看,看是否能有可用和提高的可能.


function TCnInputHelper.ParsePosInfo: Boolean;
const
  csParseBlockSize = 40 * 1024;
  csParseBlockAdd = 80;
var
  Stream: TMemoryStream;
  View: IOTAEditView;
  StartPos, CurrPos: Integer;
  Element, LineFlag: Integer;
  P: PChar;
  EditorContent:IOTAEditorContent;
  AOLEStream:TOleStream;
  ASize:Integer;
  Origin:string;
begin
  Result := False;
  View := CnOtaGetTopMostEditView;
  if not Assigned(View) then Exit;
  EditorContent:= View.Buffer as IOTAEditorContent;
  AOLEStream:=TOleStream.Create(EditorContent.Content);  //这里可以直接进入源码,不知道是否与buffer读取一样
  try
    CurrPos := CnOtaGetCurrPos(View.Buffer);
    if View.CursorPos.Line > csMaxProcessLines then
    begin
      // CnOtaEditPosToLinePos 在大文件时会很慢,此处直接使用线性位置来计算
      StartPos := Max(0, CurrPos - csParseBlockSize);
      AOLEStream.Position:=StartPos;
      ASize:=CurrPos +csParseBlockAdd-StartPos;
      SetString(Origin, nil, ASize);
      AOLEStream.Read(Pointer(Origin)^, ASize);

      FPosInfo := ParsePasCodePosInfo(Origin, CurrPos-StartPos, False);
      EditControlWrapper.GetAttributeAtPos(CnOtaGetCurrentEditControl,
        View.CursorPos, False, Element, LineFlag);
      case Element of
        atComment:
          if not (FPosInfo.PosKind in [pkComment, pkCompDirect]) then
            FPosInfo.PosKind := pkComment;
        atString:
          FPosInfo.PosKind := pkString;
      end;
    end
    else
    begin
      Stream:=TMemoryStream.Create;
      AOLEStream.Position:=0;
      Stream.LoadFromStream(AOLEStream);
      //CnOtaSaveCurrentEditorToStream(Stream, False, False);
      FPosInfo := ParsePasCodePosInfo(PChar(Stream.Memory), CurrPos, True);
    end;
  finally
    FreeMemory(AOLEStream);
    if Assigned(Stream) then
      Stream.Free;   
  end;
{$IFDEF DEBUG}
  with FPosInfo do
    CnDebugger.LogMsg(
      'TokenID: ' + GetEnumName(TypeInfo(TTokenKind), Ord(TokenID)) + #13#10 +
      'AreaKind: ' + GetEnumName(TypeInfo(TCodeAreaKind), Ord(AreaKind)) + #13#10 +
      'PosKind: ' + GetEnumName(TypeInfo(TCodePosKind), Ord(PosKind)) + #13#10 +
      'LineNumber: ' + IntToStr(LineNumber) + #13#10 +
      'LinePos: ' + IntToStr(LinePos) + #13#10 +
      'LastToken: ' + GetEnumName(TypeInfo(TTokenKind), Ord(LastNoSpace)) + #13#10 +
      'Token: ' + Token);
{$ENDIF}
  SymbolListMgr.GetValidCharSet(FirstSet, CharSet, FPosInfo);
  Result := not (FPosInfo.AreaKind in [akUnknown, akEnd]) and not
    (FPosInfo.PosKind in [pkUnknown, pkString]);
end;

别外,我把刚对跟贴的放在下面,以便引起关注:

回复 用源码制作的新版cnwizards,,好像助手的速度提高很多
我再补充一句,我刚对给周总留言时无意中想到了toolsAPI里有一句话建义使用共享内存,而我无意中使用了共享内存,所以没有慢下来,别外fastMM也使用了共享内存,
原toolsapi.pas里活是这样的

{ OTA Prefix - Open Tools API
  Accessing these interfaces only requires that the user use the Borlndmm.dll via
  sharemem. }
Top
 




All times are GMT++8, the time now is 2024-9-20 05:58

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008567 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP