Github user tarekauel commented on a diff in the pull request:
https://github.com/apache/spark/pull/7197#discussion_r33909453
--- Diff:
unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
@@ -44,60 +47,77 @@
5, 5, 5, 5,
6, 6, 6, 6};
+ /**
+ * Note: `bytes` will be hold by returned UTF8String.
+ */
public static UTF8String fromBytes(byte[] bytes) {
- return (bytes != null) ? new UTF8String().set(bytes) : null;
+ if (bytes != null) {
+ return new UTF8String(bytes, BYTE_ARRAY_OFFSET, bytes.length);
+ } else {
+ return null;
+ }
}
public static UTF8String fromString(String str) {
- return (str != null) ? new UTF8String().set(str) : null;
- }
-
- /**
- * Updates the UTF8String with String.
- */
- protected UTF8String set(final String str) {
+ if (str == null) return null;
try {
- bytes = str.getBytes("utf-8");
+ return fromBytes(str.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
// Turn the exception into unchecked so we can find out about it at
runtime, but
// don't need to add lots of boilerplate code everywhere.
- PlatformDependent.throwException(e);
+ throwException(e);
+ return null;
}
- return this;
}
- /**
- * Updates the UTF8String with byte[], which should be encoded in UTF-8.
- */
- protected UTF8String set(final byte[] bytes) {
- this.bytes = bytes;
- return this;
+ public UTF8String(Object base, long offset, int size) {
+ this.base = base;
+ this.offset = offset;
+ this.numBytes = size;
}
/**
* Returns the number of bytes for a code point with the first byte as
`b`
* @param b The first byte of a code point
*/
- public int numBytes(final byte b) {
+ public int numBytesForFirstByte(final byte b) {
--- End diff --
This could method could be static
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]