diff options
author | Stephen Toub <stoub@microsoft.com> | 2015-07-06 23:09:29 -0400 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2015-07-06 23:09:29 -0400 |
commit | 25b77bd5d2da9d2ca995928204fb70e0b12ff6b0 (patch) | |
tree | 5837659a6b25ef7d8aed522396f73a9f94ffb31f | |
parent | c2218edd754accdb521d101ca5c7f6d97eaaff23 (diff) | |
parent | 11cddd0eff920152206345acfa827df9fa855ecc (diff) | |
download | coreclr-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.cs | 37 |
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) { |