Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: kicikici on December 04, 2017, 03:39:50 pm

Title: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: kicikici on December 04, 2017, 03:39:50 pm
See attachment:
Code: [Select]
gp.pas
Comparison of executon time to another implementations which can be found on forum:
GetWord: https://forums.soldat.pl/index.php?topic=44988.0 (https://forums.soldat.pl/index.php?topic=44988.0)
GetPiece2: https://forums.soldat.pl/index.php?topic=44408.0 (https://forums.soldat.pl/index.php?topic=44408.0)

Code: [Select]
(21:31:02) /test getpiece (x.x.x.x)
(21:31:02) 50000 x GetPiece('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', ' ', 3); = 00:00:00,507
(21:31:06) /test getpiece2 (x.x.x.x)
(21:31:13) 50000 x GetPiece2('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', ' ', 3); = 00:00:05,986
(21:31:13) /test getword (x.x.x.x)
(21:31:18) 50000 x GetWord('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', 3); = 00:00:05,030
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: soldat-game on December 05, 2017, 04:51:02 pm
Nice, normal getpiece (sc2) be 0.5 ur be 0.9. (400 ms slowest) but very good
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: soldat-game on December 11, 2017, 09:30:15 am
Wooow im must test it
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: kicikici on December 11, 2017, 03:41:39 pm
Lil bit faster :P

Sure, it will be faster because you have removed code responsible for freeing allocated memory used by temporary TStringList array. It will cause memory leak. Futhermore, you have separated SplitRegExpr function outside of "try except" clause, which can also throw exception. So, it is basically bad approach. To sum up, your modifications are destroyably wrong.
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: Savage on December 11, 2017, 07:03:21 pm
U're probably right, thought it's freed automatically like local variable. I had to find some explanation, maybe this one can confirm that http://www.delphibasics.co.uk/Article.asp?Name=Memory
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: soldat-game on July 02, 2018, 12:43:43 pm
I will add more u try split example game.mp3 u must use "\" to be able to use the dot character in the expression.
example GetPiece(temp,'\.',0);
Title: Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
Post by: soldat-game on July 05, 2018, 06:00:26 am
Code: [Select]
function GetPiece(Str, Reg: string; Number: byte): string;
var
Res: TStringList;
begin
try
Res := File.CreateStringList;
SplitRegExpr(QuoteRegExprMetaChars(Reg), Str, Res);
Result:=Res.Strings[Number];
except
Result:='';
finally
Res.Free;
end;
end;

Fix