You should eliminate object
access there by copying the values to local variables.
Delphi-Quellcode:
var
Position, Size : int64;
MemoryPtr : Pointer;
PatternLen : int64;
MaxPosition : int64;
begin
...
Memory := TMemoryStream.Create;
try
Memory.CopyFrom(AStream, 0);
Memory.Position := 0;
// Work only with variables to eliminate Object access
MemoryPtr := Memory.Memory;
Position := Memory.Position;
Size := Memory.Size;
PatternLen := Length(APattern);
// No calculation of end condition
MaxPosition := Size - PatternLen + 1;
while Position < MaxPosition
do
begin
Offset := Position;
Buffer := Byte(Pointer(Longint(MemoryPtr) + Offset)^);
// ????? :(
end;