mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-09-14 14:39:04 +02:00
* Change some code that results in browser warning about unreachable code
This commit is contained in:
parent
175bd2a274
commit
738210f764
@ -530,7 +530,6 @@ class function TCustomArrayHelper<T>.BinarySearch(const AValues: array of T;
|
|||||||
const AItem: T; out AFoundIndex: SizeInt; const AComparer: IComparer<T>
|
const AItem: T; out AFoundIndex: SizeInt; const AComparer: IComparer<T>
|
||||||
): Boolean;
|
): Boolean;
|
||||||
begin
|
begin
|
||||||
Writeln('Here too',Length(aValues));
|
|
||||||
Result := BinarySearch(AValues, AItem, AFoundIndex, AComparer,
|
Result := BinarySearch(AValues, AItem, AFoundIndex, AComparer,
|
||||||
0, Length(AValues));
|
0, Length(AValues));
|
||||||
end;
|
end;
|
||||||
@ -539,7 +538,6 @@ class function TCustomArrayHelper<T>.BinarySearch(const AValues: array of T;
|
|||||||
const AItem: T; out ASearchResult: TBinarySearchResult;
|
const AItem: T; out ASearchResult: TBinarySearchResult;
|
||||||
const AComparer: IComparer<T>): Boolean;
|
const AComparer: IComparer<T>): Boolean;
|
||||||
begin
|
begin
|
||||||
Writeln('Here',Length(aValues));
|
|
||||||
Result := BinarySearch(AValues, AItem, ASearchResult, AComparer,
|
Result := BinarySearch(AValues, AItem, ASearchResult, AComparer,
|
||||||
0, Length(AValues));
|
0, Length(AValues));
|
||||||
end;
|
end;
|
||||||
@ -600,17 +598,17 @@ var
|
|||||||
imin, imax, imid, ilo: Int32;
|
imin, imax, imid, ilo: Int32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Writeln('Enter ',Length(aValues),' Idx ',aIndex,' acount: ',aCount);
|
// Writeln('Enter ',Length(aValues),' Idx ',aIndex,' acount: ',aCount);
|
||||||
// continually narrow search until just one element remains
|
// continually narrow search until just one element remains
|
||||||
imin := AIndex;
|
imin := AIndex;
|
||||||
imax := Pred(AIndex + ACount);
|
imax := Pred(AIndex + ACount);
|
||||||
Writeln('Start Imax, imin : ',Imax, ' - ', imin);
|
// Writeln('Start Imax, imin : ',Imax, ' - ', imin);
|
||||||
ilo:=imid * imid;
|
ilo:=imid * imid;
|
||||||
imid:=ilo*imid;
|
imid:=ilo*imid;
|
||||||
while (imin < imax) do
|
while (imin < imax) do
|
||||||
begin
|
begin
|
||||||
imid := (imax+imin) div 2;
|
imid := (imax+imin) div 2;
|
||||||
writeln('imid',imid);
|
// writeln('imid',imid);
|
||||||
|
|
||||||
ASearchResult.CompareResult := AComparer.Compare(AValues[imid], AItem);
|
ASearchResult.CompareResult := AComparer.Compare(AValues[imid], AItem);
|
||||||
// reduce the search
|
// reduce the search
|
||||||
@ -632,28 +630,24 @@ begin
|
|||||||
// otherwise imax == imin
|
// otherwise imax == imin
|
||||||
|
|
||||||
// deferred test for equality
|
// deferred test for equality
|
||||||
Writeln('End Imax, imin : ',Imax, ' - ', imin);
|
// Writeln('End Imax, imin : ',Imax, ' - ', imin);
|
||||||
if (imax = imin) then
|
Result:=(imax = imin);
|
||||||
begin
|
if Result then
|
||||||
|
begin
|
||||||
ASearchResult.CompareResult := AComparer.Compare(AValues[imin], AItem);
|
ASearchResult.CompareResult := AComparer.Compare(AValues[imin], AItem);
|
||||||
ASearchResult.CandidateIndex := imin;
|
ASearchResult.CandidateIndex := imin;
|
||||||
if (ASearchResult.CompareResult = 0) then
|
Result:=(ASearchResult.CompareResult = 0);
|
||||||
begin
|
if Result then
|
||||||
ASearchResult.FoundIndex := imin;
|
ASearchResult.FoundIndex := imin
|
||||||
Exit(True);
|
else
|
||||||
end else
|
|
||||||
begin
|
|
||||||
ASearchResult.FoundIndex := -1;
|
ASearchResult.FoundIndex := -1;
|
||||||
Exit(False);
|
end
|
||||||
end;
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
ASearchResult.CompareResult := 0;
|
ASearchResult.CompareResult := 0;
|
||||||
ASearchResult.FoundIndex := -1;
|
ASearchResult.FoundIndex := -1;
|
||||||
ASearchResult.CandidateIndex := -1;
|
ASearchResult.CandidateIndex := -1;
|
||||||
Exit(False);
|
end;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TArrayHelper<T>.BinarySearch(const AValues: array of T;
|
class function TArrayHelper<T>.BinarySearch(const AValues: array of T;
|
||||||
@ -696,30 +690,25 @@ begin
|
|||||||
|
|
||||||
// deferred test for equality
|
// deferred test for equality
|
||||||
LCompare := AComparer.Compare(AValues[imin], AItem);
|
LCompare := AComparer.Compare(AValues[imin], AItem);
|
||||||
if (imax = imin) and (LCompare = 0) then
|
Result:=(imax = imin) and (LCompare = 0);
|
||||||
begin
|
if Result then
|
||||||
AFoundIndex := imin;
|
AFoundIndex := imin
|
||||||
Exit(True);
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
begin
|
|
||||||
AFoundIndex := -1;
|
AFoundIndex := -1;
|
||||||
Exit(False);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TEnumerator }
|
{ TEnumerator }
|
||||||
|
|
||||||
function TEnumerator<T>.MoveNext: boolean;
|
function TEnumerator<T>.MoveNext: boolean;
|
||||||
begin
|
begin
|
||||||
Exit(DoMoveNext);
|
Result:=DoMoveNext;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TEnumerable }
|
{ TEnumerable }
|
||||||
|
|
||||||
function TEnumerable<T>.GetEnumerator: TMyEnumerator;
|
function TEnumerable<T>.GetEnumerator: TMyEnumerator;
|
||||||
begin
|
begin
|
||||||
Exit(DoGetEnumerator);
|
Result:=DoGetEnumerator;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEnumerable<T>.ToArray: TMyArray;
|
function TEnumerable<T>.ToArray: TMyArray;
|
||||||
@ -1059,9 +1048,9 @@ var
|
|||||||
begin
|
begin
|
||||||
LIndex := IndexOf(AValue);
|
LIndex := IndexOf(AValue);
|
||||||
if LIndex < 0 then
|
if LIndex < 0 then
|
||||||
Exit(Default(T));
|
Result:=Default(T)
|
||||||
|
else
|
||||||
Result := DoRemove(LIndex, cnExtracted);
|
Result := DoRemove(LIndex, cnExtracted);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TList<T>.Exchange(AIndex1, AIndex2: SizeInt);
|
procedure TList<T>.Exchange(AIndex1, AIndex2: SizeInt);
|
||||||
@ -1124,7 +1113,7 @@ begin
|
|||||||
for i := 0 to Count - 1 do
|
for i := 0 to Count - 1 do
|
||||||
if FComparer.Compare(AValue, FItems[i]) = 0 then
|
if FComparer.Compare(AValue, FItems[i]) = 0 then
|
||||||
Exit(i);
|
Exit(i);
|
||||||
Result := -1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TList<T>.LastIndexOf(const AValue: T): SizeInt;
|
function TList<T>.LastIndexOf(const AValue: T): SizeInt;
|
||||||
@ -1134,7 +1123,7 @@ begin
|
|||||||
for i := Count - 1 downto 0 do
|
for i := Count - 1 downto 0 do
|
||||||
if FComparer.Compare(AValue, FItems[i]) = 0 then
|
if FComparer.Compare(AValue, FItems[i]) = 0 then
|
||||||
Exit(i);
|
Exit(i);
|
||||||
Result := -1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TList<T>.Reverse;
|
procedure TList<T>.Reverse;
|
||||||
|
Loading…
Reference in New Issue
Block a user