Browse Source

* Patch from Martin Friebe to buffer reading dwarf info

git-svn-id: trunk@14168 -
michael 15 years ago
parent
commit
740bd6744b
1 changed files with 49 additions and 13 deletions
  1. 49 13
      rtl/inc/lnfodwrf.pp

+ 49 - 13
rtl/inc/lnfodwrf.pp

@@ -53,9 +53,13 @@ uses
 type
 type
   Bool8 = ByteBool;
   Bool8 = ByteBool;
 
 
+const
+  EBUF_SIZE = 100;
 var
 var
   { the input file to read DWARF debug info from, i.e. paramstr(0) }
   { the input file to read DWARF debug info from, i.e. paramstr(0) }
   e : TExeFile;
   e : TExeFile;
+  EBuf: Array [0..EBUF_SIZE-1] of Byte;
+  EBufCnt, EBufPos: Integer;
   DwarfErr : boolean;
   DwarfErr : boolean;
   { the offset and size of the DWARF debug_line section in the file }
   { the offset and size of the DWARF debug_line section in the file }
   DwarfOffset : longint;
   DwarfOffset : longint;
@@ -177,6 +181,8 @@ begin
   limit := aLimit;
   limit := aLimit;
   Init := (aBase + limit) <= e.size;
   Init := (aBase + limit) <= e.size;
   seek(e.f, base);
   seek(e.f, base);
+  EBufCnt := 0;
+  EBufPos := 0;
   index := 0;
   index := 0;
 end;
 end;
 
 
@@ -196,39 +202,69 @@ procedure Seek(const newIndex : Int64);
 begin
 begin
   index := newIndex;
   index := newIndex;
   system.seek(e.f, base + index);
   system.seek(e.f, base + index);
+  EBufCnt := 0;
+  EBufPos := 0;
 end;
 end;
 
 
 
 
 { Returns the next Byte from the input stream, or -1 if there has been
 { Returns the next Byte from the input stream, or -1 if there has been
   an error }
   an error }
-function ReadNext() : Longint;
+function ReadNext() : Longint; inline;
 var
 var
   bytesread : SizeInt;
   bytesread : SizeInt;
   b : Byte;
   b : Byte;
 begin
 begin
   ReadNext := -1;
   ReadNext := -1;
-  if (index < limit) then begin
-    blockread(e.f, b, 1, bytesread);
-    ReadNext := b;
-    inc(index);
+  if EBufPos >= EBufCnt then begin
+    EBufPos := 0;
+    EBufCnt := EBUF_SIZE;
+    if EBufCnt > limit - index then
+      EBufCnt := limit - index;
+    blockread(e.f, EBuf, EBufCnt, bytesread);
+    EBufCnt := bytesread;
   end;
   end;
-  if (bytesread <> 1) then
+  if EBufPos < EBufCnt then begin
+    ReadNext := EBuf[EBufPos];
+    inc(EBufPos);
+    inc(index);
+  end
+  else
     ReadNext := -1;
     ReadNext := -1;
 end;
 end;
 
 
 { Reads the next size bytes into dest. Returns true if successful,
 { Reads the next size bytes into dest. Returns true if successful,
   false otherwise. Note that dest may be partially overwritten after
   false otherwise. Note that dest may be partially overwritten after
   returning false. }
   returning false. }
-function ReadNext(var dest; size : SizeInt) : Boolean;
+function ReadNext(var dest; size : SizeInt) : Boolean; inline;
 var
 var
-  bytesread : SizeInt;
+  bytesread, totalread : SizeInt;
+  r: Boolean;
+  d: PByte;
 begin
 begin
-  bytesread := 0;
-  if ((index + size) < limit) then begin
-    blockread(e.f, dest, size, bytesread);
-    inc(index, size);
+  d := @dest;
+  totalread := 0;
+  r := True;
+  while (totalread < size) and r do begin;
+    if EBufPos >= EBufCnt then begin
+      EBufPos := 0;
+      EBufCnt := EBUF_SIZE;
+      if EBufCnt > limit - index then
+        EBufCnt := limit - index;
+      blockread(e.f, EBuf, EBufCnt, bytesread);
+      EBufCnt := bytesread;
+      if bytesread <= 0 then
+        r := False;
+    end;
+    if EBufPos < EBufCnt then begin
+      bytesread := EBufCnt - EBufPos;
+      if bytesread > size - totalread then bytesread := size - totalread;
+      System.Move(EBuf[EBufPos], d[totalread], bytesread);
+      inc(EBufPos, bytesread);
+      inc(index, bytesread);
+      inc(totalread, bytesread);
+    end;
   end;
   end;
-  ReadNext := (bytesread = size);
+  ReadNext := r;
 end;
 end;