X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2Futils.pas;h=d8b6e85c266dcf6fb2142759b53e8b5e35e913aa;hb=bee209fb79c0f1ce65b16cddd82c321488c4ba90;hp=43bdc8f015faa59bc00523c1eac0b583ad9c996b;hpb=6fdaf7454535407de0331bdc6b96e538919525a6;p=d2df-sdl.git diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 43bdc8f..d8b6e85 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -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;