Skip to content

Commit 18ac0b8

Browse files
committed
More
1 parent bd830bd commit 18ac0b8

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

server/src/main/java/org/elasticsearch/ingest/ESONXContentParser.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
package org.elasticsearch.ingest;
1111

12-
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.apache.lucene.util.BytesRef;
13+
import org.elasticsearch.common.bytes.BytesReference;
1314
import org.elasticsearch.xcontent.DeprecationHandler;
1415
import org.elasticsearch.xcontent.NamedXContentRegistry;
1516
import org.elasticsearch.xcontent.Text;
@@ -292,23 +293,20 @@ public String text() throws IOException {
292293
public XContentString optimizedText() throws IOException {
293294
// For strings, try to access raw bytes directly without materializing the string
294295
if (currentType instanceof ESONSource.VariableValue varValue && varValue.type() == ESONEntry.STRING) {
295-
// Return XContentString with direct byte access (lazy string conversion)
296-
byte[] rawBytes;
297-
int offset;
298-
int length = varValue.length();
299-
if (values.data().hasArray()) {
300-
rawBytes = values.data().array();
301-
offset = values.data().arrayOffset() + varValue.position();
296+
BytesReference slice = values.data().slice(varValue.position(), varValue.length());
297+
298+
final byte[] bytes;
299+
final int offset;
300+
if (slice.hasArray()) {
301+
bytes = slice.array();
302+
offset = slice.arrayOffset();
302303
} else {
303-
rawBytes = new byte[Math.toIntExact(length)];
304-
offset = 0;
305-
StreamInput streamInput = values.data().streamInput();
306-
streamInput.skip(varValue.position());
307-
streamInput.read(rawBytes);
304+
BytesRef bytesRef = slice.toBytesRef();
305+
bytes = bytesRef.bytes;
306+
offset = bytesRef.offset;
308307
}
309-
310308
// TODO: Fix Length
311-
return new Text(new XContentString.UTF8Bytes(rawBytes, offset, length), length);
309+
return new Text(new XContentString.UTF8Bytes(bytes, offset, varValue.length()), varValue.length());
312310
}
313311

314312
// Fallback: materialize value and convert to bytes

0 commit comments

Comments
 (0)