-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Update Text class to use native java ByteBuffer #127666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d119ca4
346e85e
c55a4c7
87afc97
ae8aa86
7114fa9
4a0ac35
e20208e
4e2e588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.xcontent; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public interface XContentString { | ||
/** | ||
* Returns a {@link String} view of the data. | ||
*/ | ||
String string(); | ||
|
||
/** | ||
* Returns a UTF8-encoded {@link ByteBuffer} view of the data. | ||
*/ | ||
ByteBuffer bytes(); | ||
|
||
/** | ||
* Returns the number of characters in the represented string. | ||
*/ | ||
int length(); | ||
ldematte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,11 @@ | |
import org.elasticsearch.common.geo.GeoPoint; | ||
import org.elasticsearch.common.io.stream.Writeable.Writer; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.text.Text; | ||
import org.elasticsearch.common.util.ByteUtils; | ||
import org.elasticsearch.core.CharArrays; | ||
import org.elasticsearch.core.Nullable; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.xcontent.Text; | ||
import org.elasticsearch.xcontent.XContentType; | ||
|
||
import java.io.IOException; | ||
|
@@ -419,7 +419,7 @@ public void writeText(Text text) throws IOException { | |
writeInt(spare.length()); | ||
write(spare.bytes(), 0, spare.length()); | ||
} else { | ||
BytesReference bytes = text.bytes(); | ||
BytesReference bytes = BytesReference.fromByteBuffer(text.bytes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could support reading/writing ByteBuffer directly in StreamInput/Output so that conversions are not necessary here. That could allow optimizing in the ByteArrayStreamInput case to create a ByteBuffer that wraps the underlying byte array with appropriate offset/length, without needing to copy bytes to a new array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into that, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm thinking this might be a bigger change than we want to incorporate into this PR. It might be better to leave it as a follow-up, since the current implementation will still work, it'll just be less optimized. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm OK with leaving this in a follow-up, it will help with reviews too |
||
writeInt(bytes.length()); | ||
bytes.writeTo(this); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.