Reduce typecasts. Use TIntegerList and TByteList where appropriate.

git-svn-id: trunk@56399 -
This commit is contained in:
juha 2017-11-13 23:20:44 +00:00
parent 5071092ea6
commit c7ba603d21
14 changed files with 95 additions and 64 deletions

View File

@ -22,6 +22,16 @@ uses
type 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>) TIntegerList = class(specialize TFPGList<Integer>)
public public
procedure Sort; overload; procedure Sort; overload;
@ -35,6 +45,16 @@ type
implementation 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; function CompareInteger(const Item1, Item2: Integer): Integer;
begin begin
Result := Item1 - Item2; Result := Item1 - Item2;
@ -45,6 +65,20 @@ begin
Result := Item1 - Item2; Result := Item1 - Item2;
end; end;
{ TByteList }
procedure TByteList.Sort;
begin
inherited Sort(@CompareByte);
end;
{ TCardinalList }
procedure TCardinalList.Sort;
begin
inherited Sort(@CompareCardinal);
end;
{ TIntegerList } { TIntegerList }
procedure TIntegerList.Sort; procedure TIntegerList.Sort;

View File

@ -837,7 +837,7 @@ end;
procedure TCustomSynMacroRecorder.SetAsString(const Value: string); procedure TCustomSynMacroRecorder.SetAsString(const Value: string);
var var
i, p, Cmd : Integer; i, p, Cmd : Longint;
S : TStrings; S : TStrings;
cmdStr : string; cmdStr : string;
iEvent: TSynMacroEvent; iEvent: TSynMacroEvent;
@ -853,9 +853,10 @@ begin
begin begin
cmdStr := Trim(S[i]); cmdStr := Trim(S[i]);
p := Pos(' ', cmdStr); p := Pos(' ', cmdStr);
if p = 0 then p := Length(cmdStr)+1; if p = 0 then
p := Length(cmdStr)+1;
Cmd := ecNone; 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 begin
Delete(cmdStr, 1, p); Delete(cmdStr, 1, p);
iEvent := CreateMacroEvent(TSynEditorCommand(Cmd)); iEvent := CreateMacroEvent(TSynEditorCommand(Cmd));

View File

@ -1335,7 +1335,7 @@ begin
MinOrigLine := MaxInt; MinOrigLine := MaxInt;
for i := 0 to aStrings.Count-1 do for i := 0 to aStrings.Count-1 do
begin begin
OriLine := Integer({%H-}PtrUInt(Pointer(aStrings.Objects[i]))); OriLine := Integer({%H-}PtrUInt(aStrings.Objects[i]));
if (OriLine > -1) and (OriLine < MinOrigLine) then if (OriLine > -1) and (OriLine < MinOrigLine) then
begin begin
MinOrigLine := OriLine; MinOrigLine := OriLine;

View File

@ -50,7 +50,7 @@ var
MsgId: Integer; MsgId: Integer;
begin begin
if (Index < 0) or (Index >= chklistCompMsg.Items.Count) then exit; 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 MsgId<=0 then exit;
if chklistCompMsg.Checked[Index] then begin if chklistCompMsg.Checked[Index] then begin
// show message, this is the default // show message, this is the default

View File

@ -215,7 +215,7 @@ var
i: Integer; i: Integer;
begin begin
OptBox.Items.Clear; 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 if ACmd = emcSynEditCommand then begin
OptBox.Enabled := True; OptBox.Enabled := True;
OptBox.Clear; OptBox.Clear;
@ -331,7 +331,7 @@ begin
if OptBox.Enabled then begin if OptBox.Enabled then begin
if MAct.Command = emcSynEditCommand 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 end
else else
MAct.Option := OptBox.ItemIndex; MAct.Option := OptBox.ItemIndex;

View File

@ -423,40 +423,38 @@ var
Result := (Flags and DT_NoPrefix) = DT_NoPrefix; Result := (Flags and DT_NoPrefix) = DT_NoPrefix;
end; end;
function Breakable(Breaks : TList; Index : Integer) : Boolean; function Breakable(Breaks : TIntegerList; Index : Integer) : Boolean;
begin begin
If not Assigned(Breaks) then If not Assigned(Breaks) then
exit(false); exit(false);
Result := Breaks.IndexOf(Pointer(PtrInt(Index))) <> -1; Result := Breaks.IndexOf(Index) <> -1;
end; end;
function NextBreakable(Breaks : TList; Index : Integer) : Integer; function NextBreakable(Breaks : TIntegerList; Index : Integer) : Integer;
begin begin
Result := -1; Result := -1;
If (not Assigned(Breaks)) or If (not Assigned(Breaks)) or (not Breakable(Breaks,Index)) then
(not Breakable(Breaks,Index))
then
exit; exit;
If Breaks.IndexOf(Pointer(PtrInt(Index))) >= Breaks.Count - 1 then If Breaks.IndexOf(Index) >= Breaks.Count - 1 then
exit; exit;
Result := integer(PtrUInt(Breaks[Breaks.IndexOf(Pointer(PtrInt(Index))) + 1])); Result := Breaks[Breaks.IndexOf(Index) + 1];
end; end;
function GetBreakablePoints(const Source : String) : TList; function GetBreakablePoints(const Source : String) : TIntegerList;
var var
I : Integer; I : Integer;
begin begin
Result := TList.Create; Result := TIntegerList.Create;
If Length(Source) < 1 then If Source = '' then
exit; exit;
For I := 1 to Length(Source) do For I := 1 to Length(Source) do
If Source[I] = ' ' then If Source[I] = ' ' then
If not Breakable(Result, I) then If not Breakable(Result, I) then
Result.Add(Pointer(PtrInt(I))); Result.Add(I);
If not Breakable(Result, Length(Source)) then If not Breakable(Result, Length(Source)) then
Result.Add(Pointer(PtrInt(Length(Source)))); Result.Add(Length(Source));
If not Breakable(Result, 0) then If not Breakable(Result, 0) then
Result.Insert(0,nil); Result.Insert(0,-1);
end; end;
function TextExtent(Handle : hDC; const Source : String) : TSize; function TextExtent(Handle : hDC; const Source : String) : TSize;
@ -495,7 +493,7 @@ var
function BreakString(const Source : String) : TStrings; function BreakString(const Source : String) : TStrings;
var var
I, FromPos, ToPos : Integer; I, FromPos, ToPos : Integer;
Breaks : TList; Breaks : TIntegerList;
begin begin
Result := TStringList.Create; Result := TStringList.Create;
Breaks := GetBreakablePoints(Source); Breaks := GetBreakablePoints(Source);

View File

@ -29,7 +29,7 @@ interface
uses uses
Types, Classes, SysUtils, Math, FPImage, Types, Classes, SysUtils, Math, FPImage,
// LazUtils // LazUtils
LazUTF8, LazUTF8, IntegerList,
// LCL // LCL
LCLType, LCLProc, LMessages, LCLPlatformDef, LCLType, LCLProc, LMessages, LCLPlatformDef,
GraphType, GraphMath, IntfGraphics, Themes; GraphType, GraphMath, IntfGraphics, Themes;

View File

@ -39,7 +39,7 @@ uses
{$EndIf} {$EndIf}
gdk2pixbuf, gtk2, gdk2, glib2, Pango, gdk2pixbuf, gtk2, gdk2, glib2, Pango,
// LazUtils // LazUtils
LazFileUtils, LazUTF8, DynHashArray, Maps, LazFileUtils, LazUTF8, DynHashArray, Maps, IntegerList,
// LCL // LCL
Dialogs, Controls, Forms, LCLStrConsts, Dialogs, Controls, Forms, LCLStrConsts,
LMessages, LCLProc, LCLIntf, LCLType, GraphType, GraphMath, LMessages, LCLProc, LCLIntf, LCLType, GraphType, GraphMath,

View File

@ -6304,7 +6304,7 @@ var
end; end;
var var
LinesList: TFPList; LinesList: TIntegerList;
LineStart, LineEnd, LineLen: integer; LineStart, LineEnd, LineLen: integer;
ArraySize, TotalSize: integer; ArraySize, TotalSize: integer;
i: integer; i: integer;
@ -6317,15 +6317,15 @@ begin
exit; exit;
end; end;
InitFont; InitFont;
LinesList:=TFPList.Create; LinesList:=TIntegerList.Create;
LineStart:=0; LineStart:=0;
// find all line starts and line ends // find all line starts and line ends
repeat repeat
LinesList.Add({%H-}Pointer(PtrInt(LineStart))); LinesList.Add(LineStart);
// find line end // find line end
LineEnd:=FindLineEnd(LineStart); LineEnd:=FindLineEnd(LineStart);
LinesList.Add({%H-}Pointer(PtrInt(LineEnd))); LinesList.Add(LineEnd);
// find next line start // find next line start
LineStart:=LineEnd; LineStart:=LineEnd;
if AText[LineStart] in [#10,#13] then begin if AText[LineStart] in [#10,#13] then begin
@ -6348,7 +6348,7 @@ begin
i:=0; i:=0;
while i<LinesList.Count do begin while i<LinesList.Count do begin
// add LineEnd - LineStart + 1 for the #0 // 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(TotalSize,LineLen);
inc(i,2); inc(i,2);
end; end;
@ -6363,8 +6363,8 @@ begin
// set the pointer to the start of the current line // set the pointer to the start of the current line
CurLineEntry[i shr 1]:=CurLineStart; CurLineEntry[i shr 1]:=CurLineStart;
// copy the line // copy the line
LineStart:=integer({%H-}PtrUInt(LinesList[i])); LineStart:=LinesList[i];
LineEnd:=integer({%H-}PtrUInt(LinesList[i+1])); LineEnd:=LinesList[i+1];
LineLen:=LineEnd-LineStart; LineLen:=LineEnd-LineStart;
if LineLen>0 then if LineLen>0 then
Move(AText[LineStart],CurLineStart^,LineLen); Move(AText[LineStart],CurLineStart^,LineLen);

View File

@ -3324,7 +3324,8 @@ var
StylesCount: Integer; StylesCount: Integer;
StylesList: TStringList; StylesList: TStringList;
y: Integer; y: Integer;
CharsetList: TFPList; CharsetList: TByteList;
CS: Byte;
function Gtk2GetFontFamiliesDefault(var AList: TStringList): Integer; function Gtk2GetFontFamiliesDefault(var AList: TStringList): Integer;
var var
@ -3507,11 +3508,12 @@ begin
FontType := TRUETYPE_FONTTYPE; FontType := TRUETYPE_FONTTYPE;
FontList := TStringList.Create; FontList := TStringList.Create;
StylesList := TStringList.Create; StylesList := TStringList.Create;
CharsetList := TFPList.Create; CharsetList := TByteList.Create;
for i := 0 to CharsetEncodingList.Count - 1 do for i := 0 to CharsetEncodingList.Count - 1 do
begin begin
if CharsetList.IndexOf({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))) = -1 then CS := TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet;
CharsetList.Add({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))); if CharsetList.IndexOf(CS) = -1 then
CharsetList.Add(CS);
end; end;
try try
if Gtk2GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily, if Gtk2GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily,
@ -3528,7 +3530,7 @@ begin
EnumLogFont.elfStyle := AStyle; EnumLogFont.elfStyle := AStyle;
if CharSetList.Count > 0 then 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); Result := Callback(EnumLogFont, Metric, FontType, LParam);
for y := 1 to StylesCount - 1 do for y := 1 to StylesCount - 1 do
@ -3539,7 +3541,7 @@ begin
end; end;
for y := 1 to CharSetList.Count - 1 do for y := 1 to CharSetList.Count - 1 do
begin begin
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[y]); EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[y];
Result := Callback(EnumLogFont, Metric, FontType, LParam); Result := Callback(EnumLogFont, Metric, FontType, LParam);
end; end;
end; end;

View File

@ -26,7 +26,7 @@ uses
{$ENDIF} {$ENDIF}
SysUtils, Classes, types, SysUtils, Classes, types,
// LazUtils // LazUtils
LazUTF8, Translations, LazUTF8, Translations, IntegerList,
// LCL // LCL
LCLPlatformDef, InterfaceBase, LCLProc, LCLStrConsts, LCLType, LMessages, LCLPlatformDef, InterfaceBase, LCLProc, LCLStrConsts, LCLType, LMessages,
Controls, Forms, FPImage, Graphics, GraphUtil, GraphType, IntfGraphics, Controls, Forms, FPImage, Graphics, GraphUtil, GraphType, IntfGraphics,

View File

@ -21,7 +21,7 @@ unit gtk3objects;
interface interface
uses uses
Classes, SysUtils, Graphics, types, LCLType, LCLProc, LazUTF8, Classes, SysUtils, Graphics, types, LCLType, LCLProc, LazUTF8, IntegerList,
LazGtk3, LazGdk3, LazGObject2, LazPango1, LazPangoCairo1, LazGdkPixbuf2, LazGtk3, LazGdk3, LazGObject2, LazPango1, LazPangoCairo1, LazGdkPixbuf2,
LazGLib2, LazCairo1, FPCanvas; LazGLib2, LazCairo1, FPCanvas;
@ -2057,7 +2057,7 @@ var
end; end;
var var
LinesList: TFPList; LinesList: TIntegerList;
LineStart, LineEnd, LineLen: integer; LineStart, LineEnd, LineLen: integer;
ArraySize, TotalSize: integer; ArraySize, TotalSize: integer;
i: integer; i: integer;
@ -2071,15 +2071,15 @@ begin
exit; exit;
end; end;
InitFont; InitFont;
LinesList:=TFPList.Create; LinesList:=TIntegerList.Create;
LineStart:=0; LineStart:=0;
// find all line starts and line ends // find all line starts and line ends
repeat repeat
LinesList.Add({%H-}Pointer(PtrInt(LineStart))); LinesList.Add(LineStart);
// find line end // find line end
LineEnd:=FindLineEnd(LineStart); LineEnd:=FindLineEnd(LineStart);
LinesList.Add({%H-}Pointer(PtrInt(LineEnd))); LinesList.Add(LineEnd);
// find next line start // find next line start
LineStart:=LineEnd; LineStart:=LineEnd;
if AText[LineStart] in [#10,#13] then if AText[LineStart] in [#10,#13] then
@ -2106,7 +2106,7 @@ begin
while i<LinesList.Count do while i<LinesList.Count do
begin begin
// add LineEnd - LineStart + 1 for the #0 // 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(TotalSize,LineLen);
inc(i,2); inc(i,2);
end; end;
@ -2122,8 +2122,8 @@ begin
// set the pointer to the start of the current line // set the pointer to the start of the current line
CurLineEntry[i shr 1]:=CurLineStart; CurLineEntry[i shr 1]:=CurLineStart;
// copy the line // copy the line
LineStart:=integer({%H-}PtrUInt(LinesList[i])); LineStart:=LinesList[i];
LineEnd:=integer({%H-}PtrUInt(LinesList[i+1])); LineEnd:=LinesList[i+1];
LineLen:=LineEnd-LineStart; LineLen:=LineEnd-LineStart;
if LineLen>0 then if LineLen>0 then
Move(AText[LineStart],CurLineStart^,LineLen); Move(AText[LineStart],CurLineStart^,LineLen);

View File

@ -1122,7 +1122,8 @@ var
StylesCount: Integer; StylesCount: Integer;
StylesList: TStringList; StylesList: TStringList;
y: Integer; y: Integer;
CharsetList: TFPList; CharsetList: TByteList;
CS: Byte;
function Gtk3GetFontFamiliesDefault(var AList: TStringList): Integer; function Gtk3GetFontFamiliesDefault(var AList: TStringList): Integer;
var var
@ -1305,11 +1306,12 @@ begin
FontType := TRUETYPE_FONTTYPE; FontType := TRUETYPE_FONTTYPE;
FontList := TStringList.Create; FontList := TStringList.Create;
StylesList := TStringList.Create; StylesList := TStringList.Create;
CharsetList := TFPList.Create; CharsetList := TByteList.Create;
for i := 0 to CharsetEncodingList.Count - 1 do for i := 0 to CharsetEncodingList.Count - 1 do
begin begin
if CharsetList.IndexOf({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))) = -1 then CS := TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet;
CharsetList.Add({%H-}Pointer(PtrUInt(TCharSetEncodingRec(CharsetEncodingList.Items[i]^).CharSet))); if CharsetList.IndexOf(CS) = -1 then
CharsetList.Add(CS);
end; end;
try try
if Gtk3GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily, if Gtk3GetFontFamilies(FontList, lpLogFont^.lfPitchAndFamily,
@ -1321,12 +1323,11 @@ begin
EnumLogFont.elfLogFont.lfPitchAndFamily := lpLogFont^.lfPitchAndFamily; EnumLogFont.elfLogFont.lfPitchAndFamily := lpLogFont^.lfPitchAndFamily;
EnumLogFont.elfFullName := FontList[i]; EnumLogFont.elfFullName := FontList[i];
StylesCount := FillLogFontA(i, EnumLogFont.elfLogFont, Metric, FontType, StylesCount := FillLogFontA(i, EnumLogFont.elfLogFont, Metric, FontType, AStyle);
AStyle);
EnumLogFont.elfStyle := AStyle; EnumLogFont.elfStyle := AStyle;
if CharSetList.Count > 0 then 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); Result := Callback(EnumLogFont, Metric, FontType, LParam);
for y := 1 to StylesCount - 1 do for y := 1 to StylesCount - 1 do
@ -1337,7 +1338,7 @@ begin
end; end;
for y := 1 to CharSetList.Count - 1 do for y := 1 to CharSetList.Count - 1 do
begin begin
EnumLogFont.elfLogFont.lfCharSet := {%H-}PtrUInt(CharsetList.Items[y]); EnumLogFont.elfLogFont.lfCharSet := CharsetList.Items[y];
Result := Callback(EnumLogFont, Metric, FontType, LParam); Result := Callback(EnumLogFont, Metric, FontType, LParam);
end; end;
end; end;

View File

@ -108,17 +108,12 @@ begin
end; end;
var var
i: Integer;
Filename1, Filename2: String;
SL: TStringListUTF8; SL: TStringListUTF8;
FromEncoding: String; Filename1, Filename2: String;
ToEncoding: String; FromEncoding, ToEncoding: String;
s: String; s: String;
UniCode: integer; UniCode: Cardinal;
CharLen: integer; TableIndex, CharLen, i, j, k: Integer;
j: Integer;
TableIndex: LongInt;
k: Integer;
begin begin
// single byte to UTF-8 // single byte to UTF-8
if ParamCount=0 then if ParamCount=0 then
@ -200,7 +195,7 @@ begin
' TableIndex[i]=',TableIndex, ' TableIndex[i]=',TableIndex,
' TableIndex[i+j]=',StrToTableIndex(SortedTable[i+j]), ' 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; break;
if StrToTableIndex(SortedTable[i+j])<>TableIndex+j then if StrToTableIndex(SortedTable[i+j])<>TableIndex+j then
break; break;