23
23
class IntlMessageParser
24
24
{
25
25
private AbstractString $ message ;
26
+ // Minor optimization, this avoid a lot of calls to `$this->message->length()`
27
+ private int $ messageLength ;
28
+
26
29
private Position $ position ;
27
30
private bool $ ignoreTag ;
28
31
private bool $ requiresOtherClause ;
@@ -31,6 +34,7 @@ public function __construct(
31
34
string $ message ,
32
35
) {
33
36
$ this ->message = s ($ message );
37
+ $ this ->messageLength = $ this ->message ->length ();
34
38
$ this ->position = new Position (0 , 1 , 1 );
35
39
$ this ->ignoreTag = true ;
36
40
$ this ->requiresOtherClause = true ;
@@ -868,7 +872,7 @@ private function tryParseDecimalInteger(
868
872
869
873
private function isEOF (): bool
870
874
{
871
- return $ this ->position ->offset === $ this ->message -> length () ;
875
+ return $ this ->position ->offset === $ this ->messageLength ;
872
876
}
873
877
874
878
/**
@@ -880,7 +884,7 @@ private function isEOF(): bool
880
884
private function char (): int
881
885
{
882
886
$ offset = $ this ->position ->offset ;
883
- if ($ offset >= $ this ->message -> length () ) {
887
+ if ($ offset >= $ this ->messageLength ) {
884
888
throw new \OutOfBoundsException ();
885
889
}
886
890
@@ -959,7 +963,7 @@ private function bumpUntil(string $pattern): bool
959
963
960
964
return true ;
961
965
} else {
962
- $ this ->bumpTo ($ this ->message -> length () );
966
+ $ this ->bumpTo ($ this ->messageLength );
963
967
964
968
return false ;
965
969
}
@@ -977,7 +981,7 @@ private function bumpTo(int $targetOffset)
977
981
throw new \Exception (\sprintf ('targetOffset %s must be greater than or equal to the current offset %d ' , $ targetOffset , $ this ->position ->offset ));
978
982
}
979
983
980
- $ targetOffset = min ($ targetOffset , $ this ->message -> length () );
984
+ $ targetOffset = min ($ targetOffset , $ this ->messageLength );
981
985
while (true ) {
982
986
$ offset = $ this ->position ->offset ;
983
987
if ($ offset === $ targetOffset ) {
0 commit comments