mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-05 09:58:27 +02:00

This fixes a bug reported by Martin Frb in fpc-devel which is triggered by the recently provided test code in FPC 3.2.2 x86_64, but is hidden in trunk by other pipeline peephole optimizations.
49 lines
873 B
ObjectPascal
49 lines
873 B
ObjectPascal
{$mode objfpc}
|
|
|
|
uses math;
|
|
|
|
type
|
|
generic TLazFifoQueue<T> = class
|
|
private
|
|
FList: array of T;
|
|
FQueueSize: integer;
|
|
protected
|
|
FTotalItemsPopped: QWord;
|
|
FTotalItemsPushed: QWord;
|
|
public
|
|
procedure Grow(ADelta: integer);
|
|
end;
|
|
|
|
procedure TLazFifoQueue.Grow(ADelta: integer);
|
|
var
|
|
NewList: array of integer;
|
|
c: Integer;
|
|
i: QWord;
|
|
begin
|
|
c:=Max(FQueueSize + ADelta, Integer(FTotalItemsPushed - FTotalItemsPopped));
|
|
setlength(NewList{%H-}, c);
|
|
i:=FTotalItemsPopped;
|
|
while i < FTotalItemsPushed do begin
|
|
NewList[i mod c] := FList[i mod FQueueSize];
|
|
inc(i);
|
|
end;
|
|
|
|
FList := NewList;
|
|
FQueueSize:=c;
|
|
end;
|
|
|
|
type
|
|
TIntQ = specialize TLazFifoQueue<integer>;
|
|
|
|
begin
|
|
with TIntQ.Create do begin
|
|
Grow(123);
|
|
if FQueueSize <> 123 then begin
|
|
writeln('FAILED');
|
|
halt(1);
|
|
end;
|
|
Free;
|
|
end;
|
|
writeln('OK');
|
|
end.
|