Ignore:
Timestamp:
Aug 6, 2024, 10:31:16 PM (2 months ago)
Author:
chronos
Message:
  • Modified: Optimized DeviceMapper read/write handlers calls without case statement.
  • Modified: Use TInt as base data type which can be redefined to different higher integer type. For start it is Int64.
Location:
branches/ByteArray
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ByteArray

    • Property svn:ignore set to
      lib
      heaptrclog.trc
      ByteArray
      ByteArray.dbg
      ByteArray.lps
      ByteArray.res
  • branches/ByteArray/Devices/Storage.pas

    r5 r9  
    44
    55uses
    6   Classes, SysUtils, Device, Channel, BigInt;
     6  Classes, SysUtils, Device, Channel, Int;
    77
    88type
     
    1919    FFile: TFileStream;
    2020    Position: Integer;
    21     function ReadByte(Address: TBigInt): Byte;
    22     function Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
    23     procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
    24     function GetAddressCount: Integer; override;
    25     procedure SetChannel(Channel: TChannel); override;
     21    function ReadByte(Address: TInt): Byte;
     22    function ReadData(Size: TIntSize): TInt;
     23    function ReadPosition(Size: TIntSize): TInt;
     24    function ReadSize(Size: TIntSize): TInt;
     25    procedure WriteData(Size: TIntSize; Value: TInt);
     26    procedure WritePosition(Size: TIntSize; Value: TInt);
     27    procedure WriteSize(Size: TIntSize; Value: TInt);
     28    function GetHandlers: THandlers; override;
    2629    constructor Create;
    2730    destructor Destroy; override;
     
    5659end;
    5760
    58 function TStorage.ReadByte(Address: TBigInt): Byte;
     61function TStorage.ReadByte(Address: TInt): Byte;
    5962begin
    6063  Result := 0;
     
    6366end;
    6467
    65 function TStorage.Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
    66 var
    67   Buffer: array of Byte;
     68function TStorage.ReadData(Size: TIntSize): TInt;
    6869begin
    69   case Integer(Address) of
    70     0: begin
    71       SetLength(Buffer, Size);
    72       FFile.Position := Position;
    73       FFile.Read(Buffer[0], Size);
    74       Result.SetByteArray(Buffer, Size);
    75       Inc(Position, Size);
    76     end;
    77     1: Result := Position;
    78     2: Result := FFile.Size;
    79   end;
     70  FFile.Position := Position;
     71  FFile.Read(Result, Size);
     72  Inc(Position, Size);
    8073end;
    8174
    82 procedure TStorage.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
    83 var
    84   Buffer: array of Byte;
     75function TStorage.ReadPosition(Size: TIntSize): TInt;
    8576begin
    86   case Integer(Address) of
    87     0: begin
    88       SetLength(Buffer, Size);
    89       Value.GetByteArray(Buffer, Size);
    90       FFile.Position := Position;
    91       FFile.Write(Buffer[1], Size);
    92       Inc(Position, Size);
    93     end;
    94     1: Position := Value;
    95     2: FFile.Size := Value;
    96   end;
     77  Result := Position;
    9778end;
    9879
    99 function TStorage.GetAddressCount: Integer;
     80function TStorage.ReadSize(Size: TIntSize): TInt;
    10081begin
    101   Result := 3;
     82  Result := FFile.Size;
    10283end;
    10384
    104 procedure TStorage.SetChannel(Channel: TChannel);
     85procedure TStorage.WriteData(Size: TIntSize; Value: TInt);
    10586begin
    106   Channel.Read := Read;
    107   Channel.Write := Write;
     87  FFile.Position := Position;
     88  FFile.Write(Value, Size);
     89  Inc(Position, Size);
     90end;
     91
     92procedure TStorage.WritePosition(Size: TIntSize; Value: TInt);
     93begin
     94  Position := Value;
     95end;
     96
     97procedure TStorage.WriteSize(Size: TIntSize; Value: TInt);
     98begin
     99  FFile.Size := Value;
     100end;
     101function TStorage.GetHandlers: THandlers;
     102begin
     103  Result := THandlers.Create;
     104  Result.ReadHandlers.Add(ReadData);
     105  Result.ReadHandlers.Add(ReadPosition);
     106  Result.ReadHandlers.Add(ReadSize);
     107  Result.WriteHandlers.Add(WriteData);
     108  Result.WriteHandlers.Add(WritePosition);
     109  Result.WriteHandlers.Add(WriteSize);
    108110end;
    109111
Note: See TracChangeset for help on using the changeset viewer.