Browse Source

+ FastBufStream.readline method added

pierre 23 years ago
parent
commit
ec56c3a4d7
3 changed files with 97 additions and 12 deletions
  1. 6 3
      ide/wcedit.pas
  2. 14 8
      ide/weditor.pas
  3. 77 1
      ide/wutils.pas

+ 6 - 3
ide/wcedit.pas

@@ -164,7 +164,7 @@ type
       procedure   PositionChanged; virtual;
       procedure   LimitsChanged; virtual;
       function    IsClipboard: Boolean; virtual;
-      function    LoadFromStream(Stream: PStream): boolean; virtual;
+      function    LoadFromStream(Stream: PFastBufStream): boolean; virtual;
       function    SaveToStream(Stream: PStream): boolean; virtual;
       function    SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual;
       destructor  Done; virtual;
@@ -1666,7 +1666,7 @@ begin
   S.Write(HighlightRow,SizeOf(HighlightRow));
 end;*)
 
-function TCodeEditor.LoadFromStream(Stream: PStream): boolean;
+function TCodeEditor.LoadFromStream(Stream: PFastBufStream): boolean;
 var OK: boolean;
 begin
   OK:=Core^.LoadFromStream(@Self,Stream);
@@ -2050,7 +2050,10 @@ end;
 END.
 {
  $Log$
- Revision 1.13  2002-09-07 15:40:47  peter
+ Revision 1.14  2002-09-09 06:58:28  pierre
+  + FastBufStream.readline method added
+
+ Revision 1.13  2002/09/07 15:40:47  peter
    * old logs removed and tabs fixed
 
  Revision 1.12  2002/09/03 11:50:08  pierre

+ 14 - 8
ide/weditor.pas

@@ -403,7 +403,7 @@ type
       function    GetLastVisibleLine : sw_integer;
     public
       { Storage }
-      function    LoadFromStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual;
+      function    LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean; virtual;
       function    SaveToStream(Editor: PCustomCodeEditor; Stream: PStream): boolean; virtual;
       function    SaveAreaToStream(Editor: PCustomCodeEditor; Stream: PStream; StartP,EndP: TPoint): boolean; virtual;
     {$ifdef TP}public{$else}protected{$endif}
@@ -538,7 +538,7 @@ type
    {a}procedure   AdjustSelectionPos(CurPosX, CurPosY: sw_integer; DeltaX, DeltaY: sw_integer);
    {a}procedure   GetContent(ALines: PUnsortedStringCollection); virtual;
    {a}procedure   SetContent(ALines: PUnsortedStringCollection); virtual;
-   {a}function    LoadFromStream(Stream: PStream): boolean; virtual;
+   {a}function    LoadFromStream(Stream: PFastBufStream): boolean; virtual;
    {a}function    SaveToStream(Stream: PStream): boolean; virtual;
    {a}function    SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual;
       function    LoadFromFile(const AFileName: string): boolean; virtual;
@@ -2805,7 +2805,7 @@ begin
   Abstract;
 end;
 
-function TCustomCodeEditor.LoadFromStream(Stream: PStream): boolean;
+function TCustomCodeEditor.LoadFromStream(Stream: PFastBufStream): boolean;
 begin
   Abstract;
   LoadFromStream:=false;
@@ -2830,7 +2830,7 @@ begin
 end;
 
 function TCustomCodeEditor.LoadFromFile(const AFileName: string): boolean;
-var S: PBufStream;
+var S: PFastBufStream;
     OK: boolean;
 begin
   New(S, Init(AFileName,stOpenRead,EditorTextBufSize));
@@ -5442,7 +5442,7 @@ end;
 
 procedure TCustomCodeEditor.ReadBlock;
 var FileName: string;
-    S: PBufStream;
+    S: PFastBufStream;
     E: PCodeEditor;
     R: TRect;
 begin
@@ -6621,7 +6621,7 @@ begin
   GetPalette:=@P;
 end;
 
-function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PStream): boolean;
+function TCustomCodeEditorCore.LoadFromStream(Editor: PCustomCodeEditor; Stream: PFastBufStream): boolean;
 var S: string;
     AllLinesComplete,LineComplete,hasCR,OK: boolean;
 begin
@@ -6635,7 +6635,10 @@ begin
    begin
      while OK and (eofstream(Stream)=false) and (GetLineCount<MaxLineCount) do
        begin
-         ReadlnFromStream(Stream,S,LineComplete,hasCR);
+         if UseFastBufStreamMethod then
+           Stream^.Readline(S,LineComplete,hasCR)
+         else
+           ReadlnFromStream(Stream,S,LineComplete,hasCR);
          AllLinesComplete:=AllLinesComplete and LineComplete;
          OK:=OK and (Stream^.Status=stOK);
          if OK then AddLine(S);
@@ -7113,7 +7116,10 @@ end;
 END.
 {
   $Log$
-  Revision 1.29  2002-09-07 15:40:48  peter
+  Revision 1.30  2002-09-09 06:58:28  pierre
+   + FastBufStream.readline method added
+
+  Revision 1.29  2002/09/07 15:40:48  peter
     * old logs removed and tabs fixed
 
   Revision 1.28  2002/09/04 14:02:54  pierre

+ 77 - 1
ide/wutils.pas

@@ -90,6 +90,7 @@ type
   TFastBufStream = object(TBufStream)
     constructor Init (FileName: FNameStr; Mode, Size: Word);
     procedure   Seek(Pos: Longint); virtual;
+    procedure Readline(var s:string;var linecomplete,hasCR : boolean);
   private
     BasePos: longint;
   end;
@@ -189,6 +190,7 @@ const LastStrToIntResult : integer = 0;
       LastStrToCardResult : integer = 0;
       LastHexToCardResult : integer = 0;
       DirSep             : char    = {$ifdef Unix}'/'{$else}'\'{$endif};
+      UseFastBufStreamMethod : boolean = false;
 
 procedure RegisterWUtils;
 
@@ -289,6 +291,7 @@ procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR
         if c<>#10 then
           stream^.seek(pos);
       end;
+
     if (c=#10) or eofstream(stream) then
       linecomplete:=true;
     if (c=#10) then
@@ -879,6 +882,76 @@ begin
     end;
 end;
 
+procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean);
+  var
+    c : char;
+    i,pos,StartPos : longint;
+    charsInS : boolean;
+  begin
+    linecomplete:=false;
+    c:=#0;
+    i:=0;
+    { this created problems for lines longer than 255 characters
+      now those lines are cutted into pieces without warning PM }
+    { changed implicit 255 to High(S), so it will be automatically extended
+      when longstrings eventually become default - Gabor }
+    if (bufend-bufptr>=High(S)) and (getpos+High(S)<getsize) then
+      begin
+        StartPos:=GetPos;
+        //read(S[1],High(S));
+        system.move(buffer^[bufptr],S[1],High(S));
+        charsInS:=true;
+      end
+    else
+      CharsInS:=false;
+
+    while (not (getpos>=getsize)) and (c<>#10) and (i<High(S)) do
+     begin
+       if CharsInS then
+         c:=s[i+1]
+       else
+         read(c,sizeof(c));
+       if c<>#10 then
+        begin
+          inc(i);
+          if not CharsInS then
+            s[i]:=c;
+        end;
+     end;
+    if CharsInS and (i<>High(S)) then
+      begin
+        if c=#10 then
+          Seek(StartPos+i+1)
+        else
+          Seek(StartPos+i);
+      end;
+    { if there was a CR LF then remove the CR Dos newline style }
+    if (i>0) and (s[i]=#13) then
+      begin
+        dec(i);
+      end;
+    if (c=#13) and (not (getpos>=getsize)) then
+      begin
+        read(c,sizeof(c));
+      end;
+    if (i=High(S)) and not (getpos>=getsize) then
+      begin
+        pos:=getpos;
+        read(c,sizeof(c));
+        if (c=#13) and not (getpos>=getsize) then
+          read(c,sizeof(c));
+        if c<>#10 then
+          seek(pos);
+      end;
+    if (c=#10) or (getpos>=getsize) then
+      linecomplete:=true;
+    if (c=#10) then
+      hasCR:=true;
+    s[0]:=chr(i);
+  end;
+
+
+
 function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
 var K1: PString absolute Key1;
     K2: PString absolute Key2;
@@ -1289,7 +1362,10 @@ BEGIN
 END.
 {
   $Log$
-  Revision 1.12  2002-09-07 15:40:50  peter
+  Revision 1.13  2002-09-09 06:58:27  pierre
+   + FastBufStream.readline method added
+
+  Revision 1.12  2002/09/07 15:40:50  peter
     * old logs removed and tabs fixed
 
   Revision 1.11  2002/09/06 09:53:53  pierre