From 9902c756e8a15bb4582cdc43bb94378f29de0999 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 13 Dec 2009 11:16:12 +0000 Subject: use TryStrToInt and TryStrToFloat instead of try .. except block may increase performance at least for medley branch git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2024 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/USong.pas | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/base/USong.pas b/src/base/USong.pas index 47200e63..151ad73d 100644 --- a/src/base/USong.pas +++ b/src/base/USong.pas @@ -96,7 +96,7 @@ type function ParseLyricStringParam(const Line: RawByteString; var LinePos: integer): RawByteString; function ParseLyricIntParam(const Line: RawByteString; var LinePos: integer): integer; - function ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): real; + function ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): extended; function ParseLyricCharParam(const Line: RawByteString; var LinePos: integer): AnsiChar; function ParseLyricText(const Line: RawByteString; var LinePos: integer): RawByteString; @@ -346,24 +346,26 @@ var begin OldLinePos := LinePos; Str := ParseLyricStringParam(Line, LinePos); - try - Result := StrToInt(Str); - except // on EConvertError + + if not TryStrToInt(Str, Result) then + begin // on convert error + Result := 0; LinePos := OldLinePos; raise EUSDXParseException.Create('Integer expected'); end; end; -function TSong.ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): real; +function TSong.ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): extended; var Str: RawByteString; OldLinePos: integer; begin OldLinePos := LinePos; Str := ParseLyricStringParam(Line, LinePos); - try - Result := StrToFloat(Str); - except // on EConvertError + + if not TryStrToFloat(Str, Result) then + begin // on convert error + Result := 0; LinePos := OldLinePos; raise EUSDXParseException.Create('Float expected'); end; -- cgit v1.2.3