Fix impl of ReadOnlySpan StartsWith/EndsWith for Unix.#16418
Conversation
|
What was the bug and what was the fix? It's not immediately obvious from the diff. |
|
For StartsWith (aside from some code cleanup in the loop): return Interop.Globalization.StartsWith(_sortHandle, b, prefix.Length - length, a, prefix.Length - length, options);Changed to: return Interop.Globalization.StartsWith(_sortHandle, b, length, a, length, options);For EndsWith: See test cases that were failing here: https://mc.dot.net/#/user/ahsonkhan/pr~2Fjenkins~2Fdotnet~2Fcorefx~2Fmaster~2F/test~2Ffunctional~2Fcli~2F/7d0fa7161a57203949b2b4f2a4da134dd10d3812/workItem/System.Memory.Tests |
|
Thanks for the explanation. I'm not 100% understanding the EndsWith case, though. These are all cases where non-ASCII was being used in the input, e.g. a soft hyphen? Why doesn't the slicing approach work for those? It hits the fallback path and then that fails? |
|
Let's take this example, which is supposed to return true - "Hello".EndsWith("ello-") return StartsWithOrdinalHelper(source.Slice(source.Length - suffix.Length), suffix, options);source.Length = 5, suffix.Length = 5, source.Slice(0) => source. Compare the first character of source with first character of suffix. H != e. Return false, which is incorrect. |
|
In that case, don't we still have a bug? We do length checks before this helper call that returns false if source.Length is < prefix/suffix.Length, but that will break an example like Maybe that's how it's supposed to behave, but it seems inconsistent that |
You are right. Good point.
We need to remove these checks: coreclr/src/mscorlib/src/System/Globalization/CompareInfo.Unix.cs Lines 282 to 285 in 154824b coreclr/src/mscorlib/src/System/Globalization/CompareInfo.Unix.cs Lines 413 to 416 in 154824b And remove the debug asserts: |
|
I recall we used to have the IsFastSort check in addition to the ignore symbols which take care of that. and the conditions at that time would be correct. |
if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options) && source.IsFastSort() && prefix.IsFastSort()) |
|
and we don't have to do IsFastSort check on Windows. |
|
to mention, checks like if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options))wouldn't be enough for Linux to optimize for ordinal. |
|
talked offline with @ahsonkhan and he pointed we check the sortable chars in the loop so I think removing the length check as suggested would be ok |

Update to #16223
Ran the new tests locally on OSX and they all pass now.
Fixes the test failures - https://ci3.dot.net/job/dotnet_corefx/job/master/job/osx-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/8584/
Related PR: dotnet/corefx#26880
cc @jkotas, @stephentoub, @KrzysztofCwalina, @tarekgh, @JeremyKuhne