Skip to content

Commit 2f3a72a

Browse files
committed
Tokenizer: Small improvement to GetNumbers() and GetLenght().
1 parent 2de1f7a commit 2f3a72a

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

PhpSerializerNET/Deserialization/PhpTokenizer.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,22 @@ private void Advance(int positons) {
5252
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5353
private string GetNumbers() {
5454
int start = this._position;
55-
int length = this._input.Slice(this._position).IndexOf((byte)';');
56-
this._position += length;
57-
return this._inputEncoding.GetString(this._input.Slice(start, length));
55+
while (this._input[this._position] != (byte)';') {
56+
this._position++;
57+
}
58+
return this._inputEncoding.GetString(this._input.Slice(start, this._position-start));
5859
}
5960

6061
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6162
private int GetLength() {
62-
int length = 0;
63-
for (; this._input[this._position] != ':'; this._position++) {
64-
length = length * 10 + (_input[_position] - 48);
63+
if (this._input[this._position+1] == ':') {
64+
return _input[_position++] - 48;
6565
}
66-
return length;
67-
}
68-
69-
70-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71-
private string GetNCharacters(int length) {
72-
return _inputEncoding.GetString(this._input.Slice(this._position, length));
66+
int start = this._position;
67+
while (this._input[this._position] != (byte)':') {
68+
this._position++;
69+
}
70+
return int.Parse(this._input.Slice(start, this._position-start));
7371
}
7472

7573
internal void GetToken() {
@@ -127,7 +125,7 @@ private void GetStringToken() {
127125
this._tokens[this._tokenPosition++] = new PhpToken(
128126
PhpDataType.String,
129127
position,
130-
this.GetNCharacters(length)
128+
_inputEncoding.GetString(this._input.Slice(this._position, length))
131129
);
132130
this.Advance(2+length);
133131
}
@@ -178,7 +176,7 @@ private void GetObjectToken() {
178176
this.Advance();
179177
int classNameLength = this.GetLength();
180178
this.Advance(2);
181-
string className = this.GetNCharacters(classNameLength);
179+
string className = _inputEncoding.GetString(this._input.Slice(this._position, classNameLength));
182180
this.Advance(2+classNameLength);
183181
int propertyCount = this.GetLength();
184182
this._tokens[this._tokenPosition++] = new PhpToken(

0 commit comments

Comments
 (0)