Skip to content

Commit dae1345

Browse files
committed
Revert "Performance: Use local variables in FastReader.readUntil() hot loops"
This reverts commit 55219cc.
1 parent 55219cc commit dae1345

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

changelog.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* Reads characters into destination buffer until one of two delimiters is found
1111
* Delimiter character is left unconsumed for subsequent read
1212
* Enables bulk string parsing optimization in json-io's JsonParser
13-
* Uses local variables instead of member fields in hot loops to enable register allocation
1413

1514
#### 4.89.0 - 2026-01-31
1615
* **PERFORMANCE**: `FastReader.getLastSnippet()` now returns bounded 200-char context

src/main/java/com/cedarsoftware/util/FastReader.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -167,57 +167,39 @@ public int readUntil(char[] dest, int off, int maxLen, char delim1, char delim2)
167167

168168
int totalRead = 0;
169169

170-
// Copy member variables to locals for faster loop access (avoids repeated field loads)
171-
final char[] localPushbackBuffer = pushbackBuffer;
172-
final int localPushbackBufferSize = pushbackBufferSize;
173-
int localPushbackPosition = pushbackPosition;
174-
final char[] localBuf = buf;
175-
int localPosition = position;
176-
int localLimit = limit;
177-
178170
// First, drain any pushback buffer
179-
while (localPushbackPosition < localPushbackBufferSize && totalRead < maxLen) {
180-
char c = localPushbackBuffer[localPushbackPosition];
171+
while (pushbackPosition < pushbackBufferSize && totalRead < maxLen) {
172+
char c = pushbackBuffer[pushbackPosition];
181173
if (c == delim1 || c == delim2) {
182174
// Found delimiter in pushback - don't consume it
183-
pushbackPosition = localPushbackPosition; // Write back before return
184175
return totalRead > 0 ? totalRead : 0;
185176
}
186177
dest[off++] = c;
187-
localPushbackPosition++;
178+
pushbackPosition++;
188179
totalRead++;
189180
}
190-
pushbackPosition = localPushbackPosition; // Write back after pushback loop
191181

192182
// Now read from main buffer
193183
while (totalRead < maxLen) {
194-
// Write back position before fill() since fill() may modify position/limit
195-
position = localPosition;
196184
fill();
197-
// Re-read after fill() since it may have changed position and limit
198-
localPosition = position;
199-
localLimit = limit;
200-
201-
if (localLimit == -1) {
185+
if (limit == -1) {
202186
// EOF reached
203187
return totalRead > 0 ? totalRead : -1;
204188
}
205189

206190
// Scan current buffer for delimiters
207-
while (localPosition < localLimit && totalRead < maxLen) {
208-
char c = localBuf[localPosition];
191+
while (position < limit && totalRead < maxLen) {
192+
char c = buf[position];
209193
if (c == delim1 || c == delim2) {
210194
// Found delimiter - don't consume it
211-
position = localPosition; // Write back before return
212195
return totalRead;
213196
}
214197
dest[off++] = c;
215-
localPosition++;
198+
position++;
216199
totalRead++;
217200
}
218201
}
219202

220-
position = localPosition; // Write back after main loop
221203
return totalRead;
222204
}
223205

0 commit comments

Comments
 (0)