summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2015-07-06 23:09:29 -0400
committerStephen Toub <stoub@microsoft.com>2015-07-06 23:09:29 -0400
commit25b77bd5d2da9d2ca995928204fb70e0b12ff6b0 (patch)
tree5837659a6b25ef7d8aed522396f73a9f94ffb31f
parentc2218edd754accdb521d101ca5c7f6d97eaaff23 (diff)
parent11cddd0eff920152206345acfa827df9fa855ecc (diff)
downloadcoreclr-25b77bd5d2da9d2ca995928204fb70e0b12ff6b0.tar.gz
coreclr-25b77bd5d2da9d2ca995928204fb70e0b12ff6b0.tar.bz2
coreclr-25b77bd5d2da9d2ca995928204fb70e0b12ff6b0.zip
Merge pull request #637 from justinvp/stringsplit
String.Split optimization
-rw-r--r--src/mscorlib/src/System/String.cs37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/mscorlib/src/System/String.cs b/src/mscorlib/src/System/String.cs
index 9d4dcde887..fbf93c9860 100644
--- a/src/mscorlib/src/System/String.cs
+++ b/src/mscorlib/src/System/String.cs
@@ -973,17 +973,26 @@ namespace System {
if ((count == 0) || (omitEmptyEntries && this.Length == 0))
{
+#if FEATURE_CORECLR
+ return EmptyArray<String>.Value;
+#else
+ // Keep the old behavior of returning a new empty array
+ // to mitigate any potential compat risk.
return new String[0];
+#endif
+ }
+
+ if (count == 1)
+ {
+ return new String[] { this };
}
int[] sepList = new int[Length];
int numReplaces = MakeSeparatorList(separator, ref sepList);
- //Handle the special case of no replaces and special count.
- if (0 == numReplaces || count == 1) {
- String[] stringArray = new String[1];
- stringArray[0] = this;
- return stringArray;
+ // Handle the special case of no replaces.
+ if (0 == numReplaces) {
+ return new String[] { this };
}
if(omitEmptyEntries)
@@ -1021,18 +1030,26 @@ namespace System {
}
if ((count == 0) || (omitEmptyEntries && this.Length ==0)) {
+#if FEATURE_CORECLR
+ return EmptyArray<String>.Value;
+#else
+ // Keep the old behavior of returning a new empty array
+ // to mitigate any potential compat risk.
return new String[0];
+#endif
+ }
+
+ if (count == 1) {
+ return new String[] { this };
}
int[] sepList = new int[Length];
int[] lengthList = new int[Length];
int numReplaces = MakeSeparatorList(separator, ref sepList, ref lengthList);
- //Handle the special case of no replaces and special count.
- if (0 == numReplaces || count == 1) {
- String[] stringArray = new String[1];
- stringArray[0] = this;
- return stringArray;
+ // Handle the special case of no replaces.
+ if (0 == numReplaces) {
+ return new String[] { this };
}
if (omitEmptyEntries) {