* explicitly use shortstring for TFPHashList

git-svn-id: trunk@6303 -
This commit is contained in:
peter 2007-02-02 18:58:29 +00:00
parent ea6204cc56
commit 06698d6e1b

View File

@ -196,14 +196,14 @@ type
FStrs : PChar; FStrs : PChar;
FStrCount, FStrCount,
FStrCapacity : Integer; FStrCapacity : Integer;
function InternalFind(AHash:LongWord;const AName:string;out PrevIndex:Integer):Integer; function InternalFind(AHash:LongWord;const AName:shortstring;out PrevIndex:Integer):Integer;
protected protected
function Get(Index: Integer): Pointer; {$ifdef CCLASSESINLINE}inline;{$endif} function Get(Index: Integer): Pointer; {$ifdef CCLASSESINLINE}inline;{$endif}
procedure Put(Index: Integer; Item: Pointer); {$ifdef CCLASSESINLINE}inline;{$endif} procedure Put(Index: Integer; Item: Pointer); {$ifdef CCLASSESINLINE}inline;{$endif}
procedure SetCapacity(NewCapacity: Integer); procedure SetCapacity(NewCapacity: Integer);
procedure SetCount(NewCount: Integer); procedure SetCount(NewCount: Integer);
Procedure RaiseIndexError(Index : Integer); Procedure RaiseIndexError(Index : Integer);
function AddStr(const s:string): Integer; function AddStr(const s:shortstring): Integer;
procedure AddToHashTable(Index: Integer); procedure AddToHashTable(Index: Integer);
procedure StrExpand(MinIncSize:Integer); procedure StrExpand(MinIncSize:Integer);
procedure SetStrCapacity(NewCapacity: Integer); procedure SetStrCapacity(NewCapacity: Integer);
@ -212,19 +212,19 @@ type
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
function Add(const AName:string;Item: Pointer): Integer; function Add(const AName:shortstring;Item: Pointer): Integer;
procedure Clear; procedure Clear;
function NameOfIndex(Index: Integer): String; {$ifdef CCLASSESINLINE}inline;{$endif} function NameOfIndex(Index: Integer): ShortString; {$ifdef CCLASSESINLINE}inline;{$endif}
function HashOfIndex(Index: Integer): LongWord; {$ifdef CCLASSESINLINE}inline;{$endif} function HashOfIndex(Index: Integer): LongWord; {$ifdef CCLASSESINLINE}inline;{$endif}
procedure Delete(Index: Integer); procedure Delete(Index: Integer);
class procedure Error(const Msg: string; Data: PtrInt); class procedure Error(const Msg: string; Data: PtrInt);
function Expand: TFPHashList; function Expand: TFPHashList;
function Extract(item: Pointer): Pointer; function Extract(item: Pointer): Pointer;
function IndexOf(Item: Pointer): Integer; function IndexOf(Item: Pointer): Integer;
function Find(const AName:string): Pointer; function Find(const AName:shortstring): Pointer;
function FindIndexOf(const AName:string): Integer; function FindIndexOf(const AName:shortstring): Integer;
function FindWithHash(const AName:string;AHash:LongWord): Pointer; function FindWithHash(const AName:shortstring;AHash:LongWord): Pointer;
function Rename(const AOldName,ANewName:string): Integer; function Rename(const AOldName,ANewName:shortstring): Integer;
function Remove(Item: Pointer): Integer; function Remove(Item: Pointer): Integer;
procedure Pack; procedure Pack;
procedure ShowStatistics; procedure ShowStatistics;
@ -251,17 +251,17 @@ type
FOwner : TFPHashObjectList; FOwner : TFPHashObjectList;
FCachedStr : pshortstring; FCachedStr : pshortstring;
FStrIndex : Integer; FStrIndex : Integer;
procedure InternalChangeOwner(HashObjectList:TFPHashObjectList;const s:string); procedure InternalChangeOwner(HashObjectList:TFPHashObjectList;const s:shortstring);
protected protected
function GetName:string;virtual; function GetName:shortstring;virtual;
function GetHash:Longword;virtual; function GetHash:Longword;virtual;
public public
constructor CreateNotOwned; constructor CreateNotOwned;
constructor Create(HashObjectList:TFPHashObjectList;const s:string); constructor Create(HashObjectList:TFPHashObjectList;const s:shortstring);
procedure ChangeOwner(HashObjectList:TFPHashObjectList); {$ifdef CCLASSESINLINE}inline;{$endif} procedure ChangeOwner(HashObjectList:TFPHashObjectList); {$ifdef CCLASSESINLINE}inline;{$endif}
procedure ChangeOwnerAndName(HashObjectList:TFPHashObjectList;const s:string); {$ifdef CCLASSESINLINE}inline;{$endif} procedure ChangeOwnerAndName(HashObjectList:TFPHashObjectList;const s:shortstring); {$ifdef CCLASSESINLINE}inline;{$endif}
procedure Rename(const ANewName:string); procedure Rename(const ANewName:shortstring);
property Name:string read GetName; property Name:shortstring read GetName;
property Hash:Longword read GetHash; property Hash:Longword read GetHash;
end; end;
@ -280,18 +280,18 @@ type
constructor Create(FreeObjects : boolean = True); constructor Create(FreeObjects : boolean = True);
destructor Destroy; override; destructor Destroy; override;
procedure Clear; procedure Clear;
function Add(const AName:string;AObject: TObject): Integer; {$ifdef CCLASSESINLINE}inline;{$endif} function Add(const AName:shortstring;AObject: TObject): Integer; {$ifdef CCLASSESINLINE}inline;{$endif}
function NameOfIndex(Index: Integer): String; {$ifdef CCLASSESINLINE}inline;{$endif} function NameOfIndex(Index: Integer): ShortString; {$ifdef CCLASSESINLINE}inline;{$endif}
function HashOfIndex(Index: Integer): LongWord; {$ifdef CCLASSESINLINE}inline;{$endif} function HashOfIndex(Index: Integer): LongWord; {$ifdef CCLASSESINLINE}inline;{$endif}
procedure Delete(Index: Integer); procedure Delete(Index: Integer);
function Expand: TFPHashObjectList; {$ifdef CCLASSESINLINE}inline;{$endif} function Expand: TFPHashObjectList; {$ifdef CCLASSESINLINE}inline;{$endif}
function Extract(Item: TObject): TObject; {$ifdef CCLASSESINLINE}inline;{$endif} function Extract(Item: TObject): TObject; {$ifdef CCLASSESINLINE}inline;{$endif}
function Remove(AObject: TObject): Integer; function Remove(AObject: TObject): Integer;
function IndexOf(AObject: TObject): Integer; {$ifdef CCLASSESINLINE}inline;{$endif} function IndexOf(AObject: TObject): Integer; {$ifdef CCLASSESINLINE}inline;{$endif}
function Find(const s:string): TObject; {$ifdef CCLASSESINLINE}inline;{$endif} function Find(const s:shortstring): TObject; {$ifdef CCLASSESINLINE}inline;{$endif}
function FindIndexOf(const s:string): Integer; {$ifdef CCLASSESINLINE}inline;{$endif} function FindIndexOf(const s:shortstring): Integer; {$ifdef CCLASSESINLINE}inline;{$endif}
function FindWithHash(const AName:string;AHash:LongWord): Pointer; function FindWithHash(const AName:shortstring;AHash:LongWord): Pointer;
function Rename(const AOldName,ANewName:string): Integer; {$ifdef CCLASSESINLINE}inline;{$endif} function Rename(const AOldName,ANewName:shortstring): Integer; {$ifdef CCLASSESINLINE}inline;{$endif}
function FindInstanceOf(AClass: TClass; AExact: Boolean; AStartAt: Integer): Integer; function FindInstanceOf(AClass: TClass; AExact: Boolean; AStartAt: Integer): Integer;
procedure Pack; {$ifdef CCLASSESINLINE}inline;{$endif} procedure Pack; {$ifdef CCLASSESINLINE}inline;{$endif}
procedure ShowStatistics; {$ifdef CCLASSESINLINE}inline;{$endif} procedure ShowStatistics; {$ifdef CCLASSESINLINE}inline;{$endif}
@ -459,7 +459,7 @@ type
end; end;
function FPHash(const s:string):LongWord; function FPHash(const s:shortstring):LongWord;
implementation implementation
@ -1010,7 +1010,7 @@ end;
TFPHashList TFPHashList
*****************************************************************************} *****************************************************************************}
function FPHash1(const s:string):LongWord; function FPHash1(const s:shortstring):LongWord;
Var Var
g : LongWord; g : LongWord;
p,pmax : pchar; p,pmax : pchar;
@ -1030,7 +1030,7 @@ end;
result:=$ffffffff; result:=$ffffffff;
end; end;
function FPHash(const s:string):LongWord; function FPHash(const s:shortstring):LongWord;
Var Var
p,pmax : pchar; p,pmax : pchar;
begin begin
@ -1075,7 +1075,7 @@ begin
end; end;
function TFPHashList.NameOfIndex(Index: Integer): String; function TFPHashList.NameOfIndex(Index: Integer): shortstring;
begin begin
If (Index < 0) or (Index >= FCount) then If (Index < 0) or (Index >= FCount) then
RaiseIndexError(Index); RaiseIndexError(Index);
@ -1185,7 +1185,7 @@ begin
end; end;
function TFPHashList.AddStr(const s:string): Integer; function TFPHashList.AddStr(const s:shortstring): Integer;
var var
Len : Integer; Len : Integer;
begin begin
@ -1213,7 +1213,7 @@ begin
end; end;
function TFPHashList.Add(const AName:string;Item: Pointer): Integer; function TFPHashList.Add(const AName:shortstring;Item: Pointer): Integer;
begin begin
if FCount = FCapacity then if FCount = FCapacity then
Expand; Expand;
@ -1324,7 +1324,7 @@ begin
end; end;
end; end;
function TFPHashList.InternalFind(AHash:LongWord;const AName:string;out PrevIndex:Integer):Integer; function TFPHashList.InternalFind(AHash:LongWord;const AName:shortstring;out PrevIndex:Integer):Integer;
var var
HashIndex : Integer; HashIndex : Integer;
Len, Len,
@ -1352,7 +1352,7 @@ begin
end; end;
function TFPHashList.Find(const AName:string): Pointer; function TFPHashList.Find(const AName:shortstring): Pointer;
var var
Index, Index,
PrevIndex : Integer; PrevIndex : Integer;
@ -1365,7 +1365,7 @@ begin
end; end;
function TFPHashList.FindIndexOf(const AName:string): Integer; function TFPHashList.FindIndexOf(const AName:shortstring): Integer;
var var
PrevIndex : Integer; PrevIndex : Integer;
begin begin
@ -1373,7 +1373,7 @@ begin
end; end;
function TFPHashList.FindWithHash(const AName:string;AHash:LongWord): Pointer; function TFPHashList.FindWithHash(const AName:shortstring;AHash:LongWord): Pointer;
var var
Index, Index,
PrevIndex : Integer; PrevIndex : Integer;
@ -1386,7 +1386,7 @@ begin
end; end;
function TFPHashList.Rename(const AOldName,ANewName:string): Integer; function TFPHashList.Rename(const AOldName,ANewName:shortstring): Integer;
var var
PrevIndex, PrevIndex,
Index : Integer; Index : Integer;
@ -1512,7 +1512,7 @@ end;
TFPHashObject TFPHashObject
*****************************************************************************} *****************************************************************************}
procedure TFPHashObject.InternalChangeOwner(HashObjectList:TFPHashObjectList;const s:string); procedure TFPHashObject.InternalChangeOwner(HashObjectList:TFPHashObjectList;const s:shortstring);
var var
Index : integer; Index : integer;
begin begin
@ -1529,7 +1529,7 @@ begin
end; end;
constructor TFPHashObject.Create(HashObjectList:TFPHashObjectList;const s:string); constructor TFPHashObject.Create(HashObjectList:TFPHashObjectList;const s:shortstring);
begin begin
InternalChangeOwner(HashObjectList,s); InternalChangeOwner(HashObjectList,s);
end; end;
@ -1541,13 +1541,13 @@ begin
end; end;
procedure TFPHashObject.ChangeOwnerAndName(HashObjectList:TFPHashObjectList;const s:string); procedure TFPHashObject.ChangeOwnerAndName(HashObjectList:TFPHashObjectList;const s:shortstring);
begin begin
InternalChangeOwner(HashObjectList,s); InternalChangeOwner(HashObjectList,s);
end; end;
procedure TFPHashObject.Rename(const ANewName:string); procedure TFPHashObject.Rename(const ANewName:shortstring);
var var
Index : integer; Index : integer;
begin begin
@ -1560,7 +1560,7 @@ begin
end; end;
function TFPHashObject.GetName:string; function TFPHashObject.GetName:shortstring;
begin begin
if FOwner<>nil then if FOwner<>nil then
begin begin
@ -1645,12 +1645,12 @@ begin
Result := FHashList.Capacity; Result := FHashList.Capacity;
end; end;
function TFPHashObjectList.Add(const AName:string;AObject: TObject): Integer; function TFPHashObjectList.Add(const AName:shortstring;AObject: TObject): Integer;
begin begin
Result := FHashList.Add(AName,AObject); Result := FHashList.Add(AName,AObject);
end; end;
function TFPHashObjectList.NameOfIndex(Index: Integer): String; function TFPHashObjectList.NameOfIndex(Index: Integer): shortstring;
begin begin
Result := FHashList.NameOfIndex(Index); Result := FHashList.NameOfIndex(Index);
end; end;
@ -1695,25 +1695,25 @@ begin
end; end;
function TFPHashObjectList.Find(const s:string): TObject; function TFPHashObjectList.Find(const s:shortstring): TObject;
begin begin
result:=TObject(FHashList.Find(s)); result:=TObject(FHashList.Find(s));
end; end;
function TFPHashObjectList.FindIndexOf(const s:string): Integer; function TFPHashObjectList.FindIndexOf(const s:shortstring): Integer;
begin begin
result:=FHashList.FindIndexOf(s); result:=FHashList.FindIndexOf(s);
end; end;
function TFPHashObjectList.FindWithHash(const AName:string;AHash:LongWord): Pointer; function TFPHashObjectList.FindWithHash(const AName:shortstring;AHash:LongWord): Pointer;
begin begin
Result:=TObject(FHashList.FindWithHash(AName,AHash)); Result:=TObject(FHashList.FindWithHash(AName,AHash));
end; end;
function TFPHashObjectList.Rename(const AOldName,ANewName:string): Integer; function TFPHashObjectList.Rename(const AOldName,ANewName:shortstring): Integer;
begin begin
Result:=FHashList.Rename(AOldName,ANewName); Result:=FHashList.Rename(AOldName,ANewName);
end; end;