DEADSOFTWARE

xdynrec: more API works
[d2df-sdl.git] / src / shared / utils.pas
index 43bdc8f015faa59bc00523c1eac0b583ad9c996b..d8b6e85c266dcf6fb2142759b53e8b5e35e913aa 100644 (file)
@@ -235,6 +235,8 @@ type
     procedure clear (); inline;
 
     procedure append (constref it: ItemT); inline;
+    procedure delete (idx: Integer); inline;
+    function remove (idx: Integer): ItemT; inline;
 
   public
     property count: Integer read mCount;
@@ -328,16 +330,46 @@ end;
 
 
 procedure TSimpleList.append (constref it: ItemT); inline;
+var
+  newsz: Integer;
 begin
-  if (mCount = Length(mItems)) then
+  if (mCount >= Length(mItems)) then
   begin
-    if (mCount = 0) then SetLength(mItems, 128) else SetLength(mItems, mCount*2);
+    newsz := mCount+(mCount div 3)+128;
+    SetLength(mItems, newsz);
   end;
   mItems[mCount] := it;
   Inc(mCount);
 end;
 
 
+procedure TSimpleList.delete (idx: Integer); inline;
+var
+  f: Integer;
+begin
+  if (idx >= 0) and (idx < mCount) then
+  begin
+    for f := idx+1 to mCount-1 do mItems[f-1] := mItems[f];
+  end;
+end;
+
+
+function TSimpleList.remove (idx: Integer): ItemT; inline;
+var
+  f: Integer;
+begin
+  if (idx >= 0) and (idx < mCount) then
+  begin
+    result := mItems[idx];
+    for f := idx+1 to mCount-1 do mItems[f-1] := mItems[f];
+  end
+  else
+  begin
+    result := Default(ItemT);
+  end;
+end;
+
+
 // ////////////////////////////////////////////////////////////////////////// //
 var
   wc2shitmap: array[0..65535] of AnsiChar;