diff options
author | Sean Owen <sowen@cloudera.com> | 2016-09-01 12:13:07 -0700 |
---|---|---|
committer | Josh Rosen <joshrosen@databricks.com> | 2016-09-01 12:13:07 -0700 |
commit | 3893e8c576cf1a6decc18701267ce7cd8caaf521 (patch) | |
tree | e7a7b61f13a348f52ae0a25162157b28203b58ca /common/unsafe/src | |
parent | 2be5f8d7e0819de03971d0af6fa310793d2d0e65 (diff) | |
download | spark-3893e8c576cf1a6decc18701267ce7cd8caaf521.tar.gz spark-3893e8c576cf1a6decc18701267ce7cd8caaf521.tar.bz2 spark-3893e8c576cf1a6decc18701267ce7cd8caaf521.zip |
[SPARK-17331][CORE][MLLIB] Avoid allocating 0-length arrays
## What changes were proposed in this pull request?
Avoid allocating some 0-length arrays, esp. in UTF8String, and by using Array.empty in Scala over Array[T]()
## How was this patch tested?
Jenkins
Author: Sean Owen <sowen@cloudera.com>
Closes #14895 from srowen/SPARK-17331.
Diffstat (limited to 'common/unsafe/src')
-rw-r--r-- | common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java index 54a5456924..dc03d893a5 100644 --- a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java +++ b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java @@ -470,7 +470,7 @@ public final class UTF8String implements Comparable<UTF8String>, Externalizable, while (e >= 0 && getByte(e) <= 0x20 && getByte(e) >= 0x00) e--; if (s > e) { // empty string - return UTF8String.fromBytes(new byte[0]); + return EMPTY_UTF8; } else { return copyUTF8String(s, e); } @@ -482,7 +482,7 @@ public final class UTF8String implements Comparable<UTF8String>, Externalizable, while (s < this.numBytes && getByte(s) <= 0x20 && getByte(s) >= 0x00) s++; if (s == this.numBytes) { // empty string - return UTF8String.fromBytes(new byte[0]); + return EMPTY_UTF8; } else { return copyUTF8String(s, this.numBytes - 1); } @@ -495,7 +495,7 @@ public final class UTF8String implements Comparable<UTF8String>, Externalizable, if (e < 0) { // empty string - return UTF8String.fromBytes(new byte[0]); + return EMPTY_UTF8; } else { return copyUTF8String(0, e); } @@ -761,7 +761,7 @@ public final class UTF8String implements Comparable<UTF8String>, Externalizable, if (numInputs == 0) { // Return an empty string if there is no input, or all the inputs are null. - return fromBytes(new byte[0]); + return EMPTY_UTF8; } // Allocate a new byte array, and copy the inputs one by one into it. |