DEADSOFTWARE

Merge branch 'master' of ssh://repo.or.cz/d2df-sdl
[d2df-sdl.git] / src / shared / mempool.pas
index 73c48c1776192ed985c023bdc5196ff86783df89..37527dde9ee617f56d647370f4515b93e4fc72fb 100644 (file)
@@ -19,6 +19,7 @@ unit mempool;
 
 interface
 
+{$IFDEF USE_MEMPOOL}
 uses
   SysUtils;
 
@@ -56,28 +57,37 @@ type
     public procedure FreeInstance (); override;
     {$ENDIF}
   end;
-
+{$ENDIF}
 
 implementation
 
+{$IFDEF USE_MEMPOOL}
 uses
   hashtable;
 
 type
-  THashPtrPtr = specialize THashBase<Pointer, PMemPool>; // key: TClass; value: PMemPool
+  THashKeyPtr = class
+  public
+    class function hash (const k: Pointer): LongWord; inline;
+    class function equ (const a, b: Pointer): Boolean; inline;
+    class procedure freekey (k: Pointer); inline;
+  end;
+
+  THashPtrPtr = specialize THashBase<Pointer, PMemPool, THashKeyPtr>; // key: TClass; value: PMemPool
 
 var
   pools: THashPtrPtr = nil;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-function hashequ (constref a, b: Pointer): Boolean; begin result := (a = b); end;
-function hashhash (constref a: Pointer): LongWord; begin result := fnvHash(PByte(@a)^, sizeof(a)); end;
+class function THashKeyPtr.hash (const k: Pointer): LongWord; inline; begin result := fnvHash(PByte(@k)^, sizeof(k)); end;
+class function THashKeyPtr.equ (const a, b: Pointer): Boolean; inline; begin result := (a = b); end;
+class procedure THashKeyPtr.freekey (k: Pointer); inline; begin end;
 
 
 function getPoolFor (c: TClass): PMemPool;
 begin
-  if (pools = nil) then pools := THashPtrPtr.Create(hashhash, hashequ);
+  if (pools = nil) then pools := THashPtrPtr.Create();
   if not pools.get(Pointer(c), result) then
   begin
     GetMem(result, sizeof(TMemPool));
@@ -181,4 +191,5 @@ finalization
   {$IF DEFINED(D2F_DEBUG) and NOT DEFINED(MEM_DISABLE_ACCOUNTING)}
   dumpPools();
   {$ENDIF}
+{$ENDIF} // USE_MEMPOOL
 end.