From 3893e8c576cf1a6decc18701267ce7cd8caaf521 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Thu, 1 Sep 2016 12:13:07 -0700 Subject: [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 Closes #14895 from srowen/SPARK-17331. --- .../src/main/java/org/apache/spark/unsafe/types/UTF8String.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common/unsafe/src/main/java') 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, 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, 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, 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, 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. -- cgit v1.2.3