mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 22:18:15 +02:00
Reduce typecasts. Use TIntegerList and TByteList where appropriate.
git-svn-id: trunk@56399 -
This commit is contained in:
parent
5071092ea6
commit
c7ba603d21
@ -22,6 +22,16 @@ uses
|
||||
|
||||
type
|
||||
|
||||
TByteList = class(specialize TFPGList<Byte>)
|
||||
public
|
||||
procedure Sort; overload;
|
||||
end;
|
||||
|
||||
TCardinalList = class(specialize TFPGList<Cardinal>)
|
||||
public
|
||||
procedure Sort; overload;
|
||||
end;
|
||||
|
||||
TIntegerList = class(specialize TFPGList<Integer>)
|
||||
public
|
||||
procedure Sort; overload;
|
||||
@ -35,6 +45,16 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
function CompareByte(const Item1, Item2: Byte): Integer;
|
||||
begin
|
||||
Result := Item1 - Item2;
|
||||
end;
|
||||
|
||||
function CompareCardinal(const Item1, Item2: Cardinal): Integer;
|
||||
begin
|
||||
Result := Item1 - Item2;
|
||||
end;
|
||||
|
||||
function CompareInteger(const Item1, Item2: Integer): Integer;
|
||||
begin
|
||||
Result := Item1 - Item2;
|
||||
@ -45,6 +65,20 @@ begin
|
||||
Result := Item1 - Item2;
|
||||
end;
|
||||
|
||||
{ TByteList }
|
||||
|
||||
procedure TByteList.Sort;
|
||||
begin
|
||||
inherited Sort(@CompareByte);
|
||||
end;
|
||||
|
||||
{ TCardinalList }
|
||||
|
||||
procedure TCardinalList.Sort;
|
||||
begin
|
||||
inherited Sort(@CompareCardinal);
|
||||
end;
|
||||
|
||||
{ TIntegerList }
|
||||
|
||||
procedure TIntegerList.Sort;
|
||||
|
@ -837,7 +837,7 @@ end;
|
||||
|
||||
procedure TCustomSynMacroRecorder.SetAsString(const Value: string);
|
||||
var
|
||||
i, p, Cmd : Integer;
|
||||
i, p, Cmd : Longint;
|
||||
S : TStrings;
|
||||
cmdStr : string;
|
||||
iEvent: TSynMacroEvent;
|
||||
@ -853,9 +853,10 @@ begin
|
||||
begin
|
||||
cmdStr := Trim(S[i]);
|
||||
p := Pos(' ', cmdStr);
|
||||
if p = 0 then p := Length(cmdStr)+1;
|
||||
if p = 0 then
|
||||
p := Length(cmdStr)+1;
|
||||
Cmd := ecNone;
|
||||
if IdentToEditorCommand(Copy(cmdStr, 1, p-1), Longint(Cmd)) then // D2 needs type-cast
|
||||
if IdentToEditorCommand(Copy(cmdStr, 1, p-1), Cmd) then
|
||||
begin
|
||||
Delete(cmdStr, 1, p);
|
||||
iEvent := CreateMacroEvent(TSynEditorCommand(Cmd));
|
||||
|
@ -1335,7 +1335,7 @@ begin
|
||||
MinOrigLine := MaxInt;
|
||||
for i := 0 to aStrings.Count-1 do
|
||||
begin
|
||||
OriLine := Integer({%H-}PtrUInt(Pointer(aStrings.Objects[i])));
|
||||
OriLine := Integer({%H-}PtrUInt(aStrings.Objects[i]));
|
||||
if (OriLine > -1) and (OriLine < MinOrigLine) then
|
||||
begin
|
||||
MinOrigLine := OriLine;
|
||||
|
@ -50,7 +50,7 @@ var
|
||||
MsgId: Integer;
|
||||
begin
|
||||
if (Index < 0) or (Index >= chklistCompMsg.Items.Count) then exit;
|
||||
MsgId:=Integer({%H-}PtrUInt(Pointer(chklistCompMsg.Items.Objects[Index])));
|
||||
MsgId:=Integer({%H-}PtrUInt(chklistCompMsg.Items.Objects[Index]));
|
||||
if MsgId<=0 then exit;
|
||||
if chklistCompMsg.Checked[Index] then begin
|
||||
// show message, this is the default
|
||||
|
@ -215,7 +215,7 @@ var
|
||||
i: Integer;
|
||||
begin
|
||||
OptBox.Items.Clear;
|
||||
ACmd := TSynEditorMouseCommand({%H-}PtrUInt(Pointer(ActionBox.items.Objects[ActionBox.ItemIndex])));
|
||||
ACmd := TSynEditorMouseCommand({%H-}PtrUInt(ActionBox.items.Objects[ActionBox.ItemIndex]));
|
||||
if ACmd = emcSynEditCommand then begin
|
||||
OptBox.Enabled := True;
|
||||
OptBox.Clear;
|
||||
@ -331,7 +331,7 @@ begin
|
||||
|
||||
if OptBox.Enabled then begin
|
||||
if MAct.Command = emcSynEditCommand then begin
|
||||
MAct.Option := TSynEditorMouseCommandOpt({%H-}PtrUInt(Pointer(OptBox.Items.Objects[OptBox.ItemIndex])));
|
||||
MAct.Option := TSynEditorMouseCommandOpt({%H-}PtrUInt(OptBox.Items.Objects[OptBox.ItemIndex]));
|
||||
end
|
||||
else
|
||||
MAct.Option := OptBox.ItemIndex;
|
||||
|
@ -423,40 +423,38 @@ var
|
||||
Result := (Flags and DT_NoPrefix) = DT_NoPrefix;
|
||||
end;
|
||||
|
||||
function Breakable(Breaks : TList; Index : Integer) : Boolean;
|
||||
function Breakable(Breaks : TIntegerList; Index : Integer) : Boolean;
|
||||
begin
|
||||
If not Assigned(Breaks) then
|
||||
exit(false);
|
||||
Result := Breaks.IndexOf(Pointer(PtrInt(Index))) <> -1;
|
||||
Result := Breaks.IndexOf(Index) <> -1;
|
||||
end;
|
||||
|
||||
function NextBreakable(Breaks : TList; Index : Integer) : Integer;
|
||||
function NextBreakable(Breaks : TIntegerList; Index : Integer) : Integer;
|
||||
begin
|
||||
Result := -1;
|
||||
If (not Assigned(Breaks)) or
|
||||
(not Breakable(Breaks,Index))
|
||||
then
|
||||
If (not Assigned(Breaks)) or (not Breakable(Breaks,Index)) then
|
||||
exit;
|
||||
If Breaks.IndexOf(Pointer(PtrInt(Index))) >= Breaks.Count - 1 then
|
||||
If Breaks.IndexOf(Index) >= Breaks.Count - 1 then
|
||||
exit;
|
||||
Result := integer(PtrUInt(Breaks[Breaks.IndexOf(Pointer(PtrInt(Index))) + 1]));
|
||||
Result := Breaks[Breaks.IndexOf(Index) + 1];
|
||||
end;
|
||||
|
||||
function GetBreakablePoints(const Source : String) : TList;
|
||||
function GetBreakablePoints(const Source : String) : TIntegerList;
|
||||
var
|
||||
I : Integer;
|
||||
begin
|
||||
Result := TList.Create;
|
||||
If Length(Source) < 1 then
|
||||
Result := TIntegerList.Create;
|
||||
If Source = '' then
|
||||
exit;
|
||||
For I := 1 to Length(Source) do
|
||||
If Source[I] = ' ' then
|
||||
If not Breakable(Result, I) then
|
||||
Result.Add(Pointer(PtrInt(I)));
|
||||
Result.Add(I);
|
||||
If not Breakable(Result, Length(Source)) then
|
||||
Result.Add(Pointer(PtrInt(Length(Source))));
|
||||
Result.Add(Length(Source));
|
||||
If not Breakable(Result, 0) then
|
||||
Result.Insert(0,nil);
|
||||
Result.Insert(0,-1);
|
||||
end;
|
||||
|
||||
function TextExtent(Handle : hDC; const Source : String) : TSize;
|
||||
@ -495,7 +493,7 @@ var
|
||||
function BreakString(const Source : String) : TStrings;
|
||||
var
|
||||
I, FromPos, ToPos : Integer;
|
||||
Breaks : TList;
|
||||
Breaks : TIntegerList;
|
||||
begin
|
||||
Result := TStringList.Create;
|
||||
Breaks := GetBreakablePoints(Source);
|
||||
|
@ -29,7 +29,7 @@ interface
|
||||
uses
|
||||
Types, Classes, SysUtils, Math, FPImage,
|
||||
// LazUtils
|
||||
LazUTF8,
|
||||
LazUTF8, IntegerList,
|
||||
// LCL
|
||||
LCLType, LCLProc, LMessages, LCLPlatformDef,
|
||||
GraphType, GraphMath, IntfGraphics, Themes;
|
||||
|
@ -39,7 +39,7 @@ uses
|
||||
{$EndIf}
|
||||
gdk2pixbuf, gtk2, gdk2, glib2, Pango,
|
||||
// LazUtils
|
||||
LazFileUtils, LazUTF8, DynHashArray, Maps,
|
||||
LazFileUtils, LazUTF8, DynHashArray, Maps, IntegerList,
|
||||
// LCL
|
||||
Dialogs, Controls, Forms, LCLStrConsts,
|
||||
LMessages, LCLProc, LCLIntf, LCLType, GraphType, GraphMath,
|
||||
|
@ -6304,7 +6304,7 @@ var
|
||||
end;
|
||||
|
||||
var
|
||||
LinesList: TFPList;
|
||||
LinesList: TIntegerList;
|
||||
LineStart, LineEnd, LineLen: integer;
|
||||
ArraySize, TotalSize: integer;
|
||||
i: integer;
|
||||
@ -6317,15 +6317,15 @@ begin
|
||||
exit;
|
||||
end;
|
||||
InitFont;
|
||||
LinesList:=TFPList.Create;
|
||||
LinesList:=TIntegerList.Create;
|
||||
LineStart:=0;
|
||||
|
||||
// find all line starts and line ends
|
||||
repeat
|
||||
LinesList.Add({%H-}Pointer(PtrInt(LineStart)));
|
||||
LinesList.Add(LineStart);
|
||||
// find line end
|
||||
LineEnd:=FindLineEnd(LineStart);
|
||||
LinesList.Add({%H-}Pointer(PtrInt(LineEnd)));
|
||||
LinesList.Add(LineEnd);
|
||||
// find next line start
|
||||
LineStart:=LineEnd;
|
||||
if AText[LineStart] in [#10,#13] then begin
|
||||
@ -6348,7 +6348,7 @@ begin
|
||||
i:=0;
|
||||
while i<LinesList.Count do begin
|
||||
// add LineEnd - LineStart + 1 for the #0
|
||||
LineLen:={%H-}PtrUInt(LinesList[i+1])-{%H-}PtrUInt(LinesList[i])+1;
|
||||
LineLen:=LinesList[i+1]-LinesList[i]+1;
|
||||
inc(TotalSize,LineLen);
|
||||
inc(i,2);
|
||||
end;
|
||||
@ -6363,8 +6363,8 @@ begin
|
||||
// set the pointer to the start of the current line
|
||||
CurLineEntry[i shr 1]:=CurLineStart;
|
||||
// copy the line
|
||||
LineStart:=integer({%H-}PtrUInt(LinesList[i]));
|
||||
LineEnd:=integer({%H-}PtrUInt(LinesList[i+1]));
|
||||
LineStart:=LinesList[i];
|
||||
LineEnd:=LinesList[i+1];
|
||||
LineLen:=LineEnd-LineStart;
|
||||
if LineLen>0 then
|
||||
Move(AText[LineStart],CurLineStart^,LineLen);
|
||||
|
@ -3324,7 +3324,8 @@ var
|
||||
StylesCount: Integer;
|
||||
StylesList: TStringList;
|
||||
y: Integer;
|
||||
CharsetList: TFPList;
|
||||
CharsetList: TByteList;
|
||||
CS: Byte;
|
||||
|
||||
function Gtk2GetFontFamiliesDefault(var AList: TStringList): Integer;
|
||||
var
|
||||
@ -3507,11 +3508,12 @@ begin
|
||||
FontType := TRUETYPE_FONTTYPE;
|
||||
FontList := TStringList.Create;
|
||||
StylesList := TStringList.Create;
|
||||
CharsetList := TFPList.Create;
|
||||
CharsetList := TByteList.Create;
|
||||
for i := 0 to CharsetEncodingList.Count - 1 do
|
||||
begin
|
||||
if CharsetList.IndexOf({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))) = -1 then
|
||||
CharsetList.Add({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet)));
|
||||
CS := TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet;
|
||||
if CharsetList.IndexOf(CS) = -1 then
|
||||
CharsetList.Add(CS);
|
||||
end;
|
||||
try
|
||||
if Gtk2GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily,
|
||||
@ -3528,7 +3530,7 @@ begin
|
||||
EnumLogFont.elfStyle := AStyle;
|
||||
|
||||
if CharSetList.Count > 0 then
|
||||
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[0]);
|
||||
EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[0];
|
||||
|
||||
Result := Callback(EnumLogFont, Metric, FontType, LParam);
|
||||
for y := 1 to StylesCount - 1 do
|
||||
@ -3539,7 +3541,7 @@ begin
|
||||
end;
|
||||
for y := 1 to CharSetList.Count - 1 do
|
||||
begin
|
||||
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[y]);
|
||||
EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[y];
|
||||
Result := Callback(EnumLogFont, Metric, FontType, LParam);
|
||||
end;
|
||||
end;
|
||||
|
@ -26,7 +26,7 @@ uses
|
||||
{$ENDIF}
|
||||
SysUtils, Classes, types,
|
||||
// LazUtils
|
||||
LazUTF8, Translations,
|
||||
LazUTF8, Translations, IntegerList,
|
||||
// LCL
|
||||
LCLPlatformDef, InterfaceBase, LCLProc, LCLStrConsts, LCLType, LMessages,
|
||||
Controls, Forms, FPImage, Graphics, GraphUtil, GraphType, IntfGraphics,
|
||||
|
@ -21,7 +21,7 @@ unit gtk3objects;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Graphics, types, LCLType, LCLProc, LazUTF8,
|
||||
Classes, SysUtils, Graphics, types, LCLType, LCLProc, LazUTF8, IntegerList,
|
||||
LazGtk3, LazGdk3, LazGObject2, LazPango1, LazPangoCairo1, LazGdkPixbuf2,
|
||||
LazGLib2, LazCairo1, FPCanvas;
|
||||
|
||||
@ -2057,7 +2057,7 @@ var
|
||||
end;
|
||||
|
||||
var
|
||||
LinesList: TFPList;
|
||||
LinesList: TIntegerList;
|
||||
LineStart, LineEnd, LineLen: integer;
|
||||
ArraySize, TotalSize: integer;
|
||||
i: integer;
|
||||
@ -2071,15 +2071,15 @@ begin
|
||||
exit;
|
||||
end;
|
||||
InitFont;
|
||||
LinesList:=TFPList.Create;
|
||||
LinesList:=TIntegerList.Create;
|
||||
LineStart:=0;
|
||||
|
||||
// find all line starts and line ends
|
||||
repeat
|
||||
LinesList.Add({%H-}Pointer(PtrInt(LineStart)));
|
||||
LinesList.Add(LineStart);
|
||||
// find line end
|
||||
LineEnd:=FindLineEnd(LineStart);
|
||||
LinesList.Add({%H-}Pointer(PtrInt(LineEnd)));
|
||||
LinesList.Add(LineEnd);
|
||||
// find next line start
|
||||
LineStart:=LineEnd;
|
||||
if AText[LineStart] in [#10,#13] then
|
||||
@ -2106,7 +2106,7 @@ begin
|
||||
while i<LinesList.Count do
|
||||
begin
|
||||
// add LineEnd - LineStart + 1 for the #0
|
||||
LineLen:={%H-}PtrUInt(LinesList[i+1])-{%H-}PtrUInt(LinesList[i])+1;
|
||||
LineLen:=LinesList[i+1]-LinesList[i]+1;
|
||||
inc(TotalSize,LineLen);
|
||||
inc(i,2);
|
||||
end;
|
||||
@ -2122,8 +2122,8 @@ begin
|
||||
// set the pointer to the start of the current line
|
||||
CurLineEntry[i shr 1]:=CurLineStart;
|
||||
// copy the line
|
||||
LineStart:=integer({%H-}PtrUInt(LinesList[i]));
|
||||
LineEnd:=integer({%H-}PtrUInt(LinesList[i+1]));
|
||||
LineStart:=LinesList[i];
|
||||
LineEnd:=LinesList[i+1];
|
||||
LineLen:=LineEnd-LineStart;
|
||||
if LineLen>0 then
|
||||
Move(AText[LineStart],CurLineStart^,LineLen);
|
||||
|
@ -1122,7 +1122,8 @@ var
|
||||
StylesCount: Integer;
|
||||
StylesList: TStringList;
|
||||
y: Integer;
|
||||
CharsetList: TFPList;
|
||||
CharsetList: TByteList;
|
||||
CS: Byte;
|
||||
|
||||
function Gtk3GetFontFamiliesDefault(var AList: TStringList): Integer;
|
||||
var
|
||||
@ -1305,11 +1306,12 @@ begin
|
||||
FontType := TRUETYPE_FONTTYPE;
|
||||
FontList := TStringList.Create;
|
||||
StylesList := TStringList.Create;
|
||||
CharsetList := TFPList.Create;
|
||||
CharsetList := TByteList.Create;
|
||||
for i := 0 to CharsetEncodingList.Count - 1 do
|
||||
begin
|
||||
if CharsetList.IndexOf({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))) = -1 then
|
||||
CharsetList.Add({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet)));
|
||||
CS := TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet;
|
||||
if CharsetList.IndexOf(CS) = -1 then
|
||||
CharsetList.Add(CS);
|
||||
end;
|
||||
try
|
||||
if Gtk3GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily,
|
||||
@ -1321,12 +1323,11 @@ begin
|
||||
EnumLogFont.elfLogFont.lfPitchAndFamily := lpLogFont^.lfPitchAndFamily;
|
||||
EnumLogFont.elfFullName := FontList[i];
|
||||
|
||||
StylesCount := FillLogFontA(i, EnumLogFont.elfLogFont, Metric, FontType,
|
||||
AStyle);
|
||||
StylesCount := FillLogFontA(i, EnumLogFont.elfLogFont, Metric, FontType, AStyle);
|
||||
EnumLogFont.elfStyle := AStyle;
|
||||
|
||||
if CharSetList.Count > 0 then
|
||||
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[0]);
|
||||
EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[0];
|
||||
|
||||
Result := Callback(EnumLogFont, Metric, FontType, LParam);
|
||||
for y := 1 to StylesCount - 1 do
|
||||
@ -1337,7 +1338,7 @@ begin
|
||||
end;
|
||||
for y := 1 to CharSetList.Count - 1 do
|
||||
begin
|
||||
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[y]);
|
||||
EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[y];
|
||||
Result := Callback(EnumLogFont, Metric, FontType, LParam);
|
||||
end;
|
||||
end;
|
||||
|
@ -108,17 +108,12 @@ begin
|
||||
end;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
Filename1, Filename2: String;
|
||||
SL: TStringListUTF8;
|
||||
FromEncoding: String;
|
||||
ToEncoding: String;
|
||||
Filename1, Filename2: String;
|
||||
FromEncoding, ToEncoding: String;
|
||||
s: String;
|
||||
UniCode: integer;
|
||||
CharLen: integer;
|
||||
j: Integer;
|
||||
TableIndex: LongInt;
|
||||
k: Integer;
|
||||
UniCode: Cardinal;
|
||||
TableIndex, CharLen, i, j, k: Integer;
|
||||
begin
|
||||
// single byte to UTF-8
|
||||
if ParamCount=0 then
|
||||
@ -200,7 +195,7 @@ begin
|
||||
' TableIndex[i]=',TableIndex,
|
||||
' TableIndex[i+j]=',StrToTableIndex(SortedTable[i+j]),
|
||||
'');}
|
||||
if integer(UTF8CharacterToUnicode(@SortedTable[i+j][1],CharLen))<>UniCode+j then
|
||||
if UTF8CharacterToUnicode(@SortedTable[i+j][1],CharLen)<>UniCode+j then
|
||||
break;
|
||||
if StrToTableIndex(SortedTable[i+j])<>TableIndex+j then
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user