Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Change calls from string.IndexOf to string.Contains (CoreFX) #32249

Merged
merged 15 commits into from Sep 13, 2018

Conversation

grant-d
Copy link

@grant-d grant-d commented Sep 12, 2018

  • See https://github.com/dotnet/corefx/issues/27526 : Contains is optimized over IndexOf
  • Found additional (~40) callsites that can take advantage of Span<T>.Contains
  • Reverted a few (~16) callsites that cross-compile to frameworks that don't support Span<T>.Contains
  • Units

@grant-d grant-d changed the title Change calls from string.IndexOf to string.Contains Change calls from string.IndexOf to string.Contains (CoreFX) Sep 12, 2018
@grant-d grant-d changed the title Change calls from string.IndexOf to string.Contains (CoreFX) Change calls from string.IndexOf to string.Contains (CoreFX) - WIP Sep 12, 2018
@@ -174,7 +174,7 @@ public static void EncodeTags(int tags, ref int pos, byte[] metadata)

public static void CheckName(string name)
{
if (name != null && 0 <= name.IndexOf('\0'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you don't need to make the changes to src/Common/src/CoreLib/* again here.
The changes from dotnet/coreclr#19874 will get mirrored to this repository automatically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #32252

Copy link
Author

@grant-d grant-d Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, didn't realize that. Thanks.

src/Common/src/CoreLib/System/Diagnostics/Tracing/TraceLogging/Statics.cs
src/Common/src/CoreLib/System/Globalization/CalendarData.Unix.cs
src/Common/src/CoreLib/System/Globalization/CultureData.cs
src/Common/src/CoreLib/System/IO/Path.Unix.cs
src/Common/src/CoreLib/System/IO/Path.Windows.cs
src/Common/src/CoreLib/System/IO/PathHelper.Windows.cs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted those files

@grant-d
Copy link
Author

grant-d commented Sep 12, 2018

@ahsonkhan please can you let me know what dotnet-bot command I use to kick off all the tests?
I tried test this and test CI to no avail

@grant-d
Copy link
Author

grant-d commented Sep 12, 2018

Also. Would this build typically succeed now that the reference assembly code has been checked in (the other PR you merged today). Or do I need to wait for an SDK push or the like

@ahsonkhan
Copy link
Member

please can you let me know what dotnet-bot command I use to kick off all the tests?

It's dotnet-bot test this please

;)

You can also use @dotnet-bot help

@ahsonkhan
Copy link
Member

@dotnet-bot help

@dotnet-bot
Copy link

Welcome to the dotnet/corefx Repository

The following is a list of valid commands on this PR. To invoke a command, comment the indicated phrase on the PR

The following commands are valid for all PRs and repositories.

Click to expand
Comment Phrase Action
@dotnet-bot test this please Re-run all legs. Use sparingly
@dotnet-bot test ci please Generates (but does not run) jobs based on changes to the groovy job definitions in this branch
@dotnet-bot help Print this help message

The following jobs are launched by default for each PR against dotnet/corefx:master.

Click to expand
Comment Phrase Job Launched
@dotnet-bot test Linux arm64 Release Build Linux arm64 Release Build
@dotnet-bot test Linux x64 Release Build Linux x64 Release Build
@dotnet-bot test Linux-musl x64 Debug Build Linux-musl x64 Debug Build
@dotnet-bot test OSX x64 Debug Build OSX x64 Debug Build
@dotnet-bot test Packaging All Configurations x64 Debug Build Packaging All Configurations x64 Debug Build
@dotnet-bot test Windows x64 Debug Build Windows x64 Debug Build
@dotnet-bot test Windows x86 Release Build Windows x86 Release Build
@dotnet-bot test NETFX x86 Release Build NETFX x86 Release Build
@dotnet-bot test UWP CoreCLR x64 Debug Build UWP CoreCLR x64 Debug Build
@dotnet-bot test UWP NETNative x86 Release Build UWP NETNative x86 Release Build

The following optional jobs are available in PRs against dotnet/corefx:master.

Click to expand
Comment Phrase Job Launched
@dotnet-bot test CentOS.6 x64 Debug Build Queues CentOS.6 x64 Debug Build
@dotnet-bot test Outerloop CentOS.6 x64 Debug Build Queues Outerloop CentOS.6 x64 Debug Build
@dotnet-bot test CentOS.6 x64 Release Build Queues CentOS.6 x64 Release Build
@dotnet-bot test Outerloop CentOS.6 x64 Release Build Queues Outerloop CentOS.6 x64 Release Build
@dotnet-bot test Linux arm64 Debug Build Queues Linux arm64 Debug Build
@dotnet-bot test Outerloop Linux arm64 Debug Build Queues Outerloop Linux arm64 Debug Build
@dotnet-bot test Linux x64 Debug Build Queues Linux x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build Queues Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop Linux arm64 Release Build Queues Outerloop Linux arm64 Release Build
@dotnet-bot test Outerloop Linux x64 Release Build Queues Outerloop Linux x64 Release Build
@dotnet-bot test Outerloop Linux-musl x64 Debug Build Queues Outerloop Linux-musl x64 Debug Build
@dotnet-bot test Linux-musl x64 Release Build Queues Linux-musl x64 Release Build
@dotnet-bot test Outerloop Linux-musl x64 Release Build Queues Outerloop Linux-musl x64 Release Build
@dotnet-bot test Outerloop OSX x64 Debug Build Queues Outerloop OSX x64 Debug Build
@dotnet-bot test OSX x64 Release Build Queues OSX x64 Release Build
@dotnet-bot test Outerloop OSX x64 Release Build Queues Outerloop OSX x64 Release Build
@dotnet-bot test Outerloop Packaging All Configurations x64 Debug Build Queues Outerloop Packaging All Configurations x64 Debug Build
@dotnet-bot test Packaging All Configurations x86 Debug Build Queues Packaging All Configurations x86 Debug Build
@dotnet-bot test Outerloop Packaging All Configurations x86 Debug Build Queues Outerloop Packaging All Configurations x86 Debug Build
@dotnet-bot test Packaging All Configurations x64 Release Build Queues Packaging All Configurations x64 Release Build
@dotnet-bot test Outerloop Packaging All Configurations x64 Release Build Queues Outerloop Packaging All Configurations x64 Release Build
@dotnet-bot test Packaging All Configurations x86 Release Build Queues Packaging All Configurations x86 Release Build
@dotnet-bot test Outerloop Packaging All Configurations x86 Release Build Queues Outerloop Packaging All Configurations x86 Release Build
@dotnet-bot test Outerloop Windows x64 Debug Build Queues Outerloop Windows x64 Debug Build
@dotnet-bot test Windows x86 Debug Build Queues Windows x86 Debug Build
@dotnet-bot test Outerloop Windows x86 Debug Build Queues Outerloop Windows x86 Debug Build
@dotnet-bot test Windows x64 Release Build Queues Windows x64 Release Build
@dotnet-bot test Outerloop Windows x64 Release Build Queues Outerloop Windows x64 Release Build
@dotnet-bot test Outerloop Windows x86 Release Build Queues Outerloop Windows x86 Release Build
@dotnet-bot test NETFX x64 Debug Build Queues NETFX x64 Debug Build
@dotnet-bot test Outerloop NETFX x64 Debug Build Queues Outerloop NETFX x64 Debug Build
@dotnet-bot test NETFX x86 Debug Build Queues NETFX x86 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build Queues Outerloop NETFX x86 Debug Build
@dotnet-bot test NETFX x64 Release Build Queues NETFX x64 Release Build
@dotnet-bot test Outerloop NETFX x64 Release Build Queues Outerloop NETFX x64 Release Build
@dotnet-bot test Outerloop NETFX x86 Release Build Queues Outerloop NETFX x86 Release Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Debug Build Queues Outerloop UWP CoreCLR x64 Debug Build
@dotnet-bot test UWP CoreCLR x86 Debug Build Queues UWP CoreCLR x86 Debug Build
@dotnet-bot test Outerloop UWP CoreCLR x86 Debug Build Queues Outerloop UWP CoreCLR x86 Debug Build
@dotnet-bot test UWP CoreCLR x64 Release Build Queues UWP CoreCLR x64 Release Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Release Build Queues Outerloop UWP CoreCLR x64 Release Build
@dotnet-bot test UWP CoreCLR x86 Release Build Queues UWP CoreCLR x86 Release Build
@dotnet-bot test Outerloop UWP CoreCLR x86 Release Build Queues Outerloop UWP CoreCLR x86 Release Build
@dotnet-bot test UWP NETNative x64 Debug Build Queues UWP NETNative x64 Debug Build
@dotnet-bot test Outerloop UWP NETNative x64 Debug Build Queues Outerloop UWP NETNative x64 Debug Build
@dotnet-bot test UWP NETNative x86 Debug Build Queues UWP NETNative x86 Debug Build
@dotnet-bot test Outerloop UWP NETNative x86 Debug Build Queues Outerloop UWP NETNative x86 Debug Build
@dotnet-bot test UWP NETNative x64 Release Build Queues UWP NETNative x64 Release Build
@dotnet-bot test Outerloop UWP NETNative x64 Release Build Queues Outerloop UWP NETNative x64 Release Build
@dotnet-bot test Outerloop UWP NETNative x86 Release Build Queues Outerloop UWP NETNative x86 Release Build

Have a nice day!

@ahsonkhan
Copy link
Member

@dotnet-bot test this please

@dotnet-bot
Copy link

Welcome to the dotnet/corefx Repository

The following is a list of valid commands on this PR. To invoke a command, comment the indicated phrase on the PR

The following commands are valid for all PRs and repositories.

Click to expand
Comment Phrase Action
@dotnet-bot test this please Re-run all legs. Use sparingly
@dotnet-bot test ci please Generates (but does not run) jobs based on changes to the groovy job definitions in this branch
@dotnet-bot help Print this help message

The following jobs are launched by default for each PR against dotnet/corefx:master.

Click to expand
Comment Phrase Job Launched
@dotnet-bot test \QLinux arm Release Build\E Linux arm Release Build

The following optional jobs are available in PRs against dotnet/corefx:master.

Click to expand
Comment Phrase Job Launched
@dotnet-bot test innerloop CentOS7.1 Debug Queues Innerloop CentOS7.1 Debug x64 Build and Test
@dotnet-bot test innerloop CentOS7.1 Release Queues Innerloop CentOS7.1 Release x64 Build and Test
@dotnet-bot test code coverage Queues Code Coverage Windows Debug
@dotnet-bot test innerloop Debian8.4 Debug Queues Innerloop Debian8.4 Debug x64 Build and Test
@dotnet-bot test innerloop Debian8.4 Release Queues Innerloop Debian8.4 Release x64 Build and Test
@dotnet-bot test innerloop Fedora24 Debug Queues Innerloop Fedora24 Debug x64 Build and Test
@dotnet-bot test innerloop Fedora24 Release Queues Innerloop Fedora24 Release x64 Build and Test
@dotnet-bot test Linux arm Debug Queues Linux arm Debug Build
@dotnet-bot test code formatter check Queues Code Formatter Check
@dotnet-bot test innerloop OSX10.12 Debug Queues Innerloop OSX10.12 Debug x64 Build and Test
@dotnet-bot test innerloop OSX10.12 Release Queues Innerloop OSX10.12 Release x64 Build and Test
@dotnet-bot test outerloop netcoreapp CentOS7.1 Debug Queues OuterLoop netcoreapp CentOS7.1 Debug x64
@dotnet-bot test outerloop netcoreapp CentOS7.1 Release Queues OuterLoop netcoreapp CentOS7.1 Release x64
@dotnet-bot test outerloop netcoreapp Debian8.4 Debug Queues OuterLoop netcoreapp Debian8.4 Debug x64
@dotnet-bot test outerloop netcoreapp Debian8.4 Release Queues OuterLoop netcoreapp Debian8.4 Release x64
@dotnet-bot test outerloop netcoreapp Fedora24 Debug Queues OuterLoop netcoreapp Fedora24 Debug x64
@dotnet-bot test outerloop netcoreapp Fedora24 Release Queues OuterLoop netcoreapp Fedora24 Release x64
@dotnet-bot test outerloop netcoreapp OSX10.12 Debug Queues OuterLoop netcoreapp OSX10.12 Debug x64
@dotnet-bot test outerloop netcoreapp OSX10.12 Release Queues OuterLoop netcoreapp OSX10.12 Release x64
@dotnet-bot test outerloop netcoreapp PortableLinux Debug Queues OuterLoop netcoreapp PortableLinux Debug x64
@dotnet-bot test outerloop netcoreapp PortableLinux Release Queues OuterLoop netcoreapp PortableLinux Release x64
@dotnet-bot test outerloop netcoreapp RHEL7.2 Debug Queues OuterLoop netcoreapp RHEL7.2 Debug x64
@dotnet-bot test outerloop netcoreapp RHEL7.2 Release Queues OuterLoop netcoreapp RHEL7.2 Release x64
@dotnet-bot test outerloop netcoreapp Ubuntu14.04 Debug Queues OuterLoop netcoreapp Ubuntu14.04 Debug x64
@dotnet-bot test outerloop netcoreapp Ubuntu14.04 Release Queues OuterLoop netcoreapp Ubuntu14.04 Release x64
@dotnet-bot test outerloop netcoreapp Ubuntu16.04 Debug Queues OuterLoop netcoreapp Ubuntu16.04 Debug x64
@dotnet-bot test outerloop netcoreapp Ubuntu16.04 Release Queues OuterLoop netcoreapp Ubuntu16.04 Release x64
@dotnet-bot test outerloop netcoreapp Ubuntu16.10 Debug Queues OuterLoop netcoreapp Ubuntu16.10 Debug x64
@dotnet-bot test outerloop netcoreapp Ubuntu16.10 Release Queues OuterLoop netcoreapp Ubuntu16.10 Release x64
@dotnet-bot test outerloop netcoreapp Windows 7 Debug Queues OuterLoop netcoreapp Windows 7 Debug x64
@dotnet-bot test outerloop netcoreapp Windows 7 Release Queues OuterLoop netcoreapp Windows 7 Release x64
@dotnet-bot test outerloop netcoreapp Windows_NT Debug Queues OuterLoop netcoreapp Windows_NT Debug x64
@dotnet-bot test outerloop netcoreapp Windows_NT Release Queues OuterLoop netcoreapp Windows_NT Release x64
@dotnet-bot test innerloop PortableLinux Debug Queues Innerloop PortableLinux Debug x64 Build and Test
@dotnet-bot test innerloop PortableLinux Release Queues Innerloop PortableLinux Release x64 Build and Test
@dotnet-bot test innerloop RHEL7.2 Debug Queues Innerloop RHEL7.2 Debug x64 Build and Test
@dotnet-bot test innerloop RHEL7.2 Release Queues Innerloop RHEL7.2 Release x64 Build and Test
@dotnet-bot test Tizen armel Debug Queues Tizen armel Debug Build
@dotnet-bot test Tizen armel Release Queues Tizen armel Release Build
@dotnet-bot test innerloop Ubuntu14.04 Debug Queues Innerloop Ubuntu14.04 Debug x64 Build and Test
@dotnet-bot test innerloop Ubuntu14.04 Release Queues Innerloop Ubuntu14.04 Release x64 Build and Test
@dotnet-bot test innerloop Ubuntu16.04 Debug Queues Innerloop Ubuntu16.04 Debug x64 Build and Test
@dotnet-bot test innerloop Ubuntu16.04 Release Queues Innerloop Ubuntu16.04 Release x64 Build and Test
@dotnet-bot test innerloop Ubuntu16.10 Debug Queues Innerloop Ubuntu16.10 Debug x64 Build and Test
@dotnet-bot test innerloop Ubuntu16.10 Release Queues Innerloop Ubuntu16.10 Release x64 Build and Test
@dotnet-bot test innerloop Windows_NT Debug Queues Innerloop Windows_NT Debug x86 Build and Test
@dotnet-bot test innerloop Windows_NT Release Queues Innerloop Windows_NT Release x64 Build and Test

Have a nice day!

@ahsonkhan
Copy link
Member

ahsonkhan commented Sep 12, 2018

Would this build typically succeed now that the reference assembly code has been checked in

I believe it should succeed now. Let's find out :)

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

It's dotnet-bot test this please

Ha! Serves me right, where's my manners

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

@dotnet-bot test this please

@ahsonkhan
Copy link
Member

ahsonkhan commented Sep 13, 2018

Hmm... I just realized string.Contains(char) is a .NET Core 2.1+ specific API which is why you are seeing errors around overload matching not working as expected. It is looking for the API that accepts a char but can only find the one that takes string.

For certain libraries (that are cross-compiled for different runtimes), you would either need to use #ifdef OR continue to use IndexOf. For instance:

<SupportedFramework>netcoreapp2.0;net461;$(AllXamarinFrameworks)</SupportedFramework>

https://ci3.dot.net/job/dotnet_corefx/job/master/job/windows-TGroup_netcoreapp+CGroup_Release+AGroup_x86+TestOuter_false_prtest/16408/console

17:27:05 Microsoft\CSharp\CSharpCodeGenerator.cs(287,78): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.CodeDom\src\System.CodeDom.csproj]
17:27:05 Microsoft\VisualBasic\VBCodeGenerator.cs(869,40): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.CodeDom\src\System.CodeDom.csproj]
17:27:05 D:\j\workspace\windows-TGrou---f8ac6754\src\Common\src\System\CodeDom\CodeTypeReference.cs(271,57): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.CodeDom\src\System.CodeDom.csproj]
17:27:05 System\Configuration\ConfigurationProperty.cs(137,67): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj]
17:27:05 System\Configuration\ConfigurationSectionCollection.cs(96,31): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj]
17:27:05 System\Configuration\ConfigurationSectionGroupCollection.cs(93,31): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj]
17:27:05 System\Configuration\TypeUtil.cs(53,73): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj]
17:27:05 System\Configuration\BaseConfigurationRecord.cs(3221,39): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---f8ac6754\src\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj]

For these specific failures (System.Config/Microsoft.CSharp/etc.), I would keep using IndexOf to keep things simple (unless they already have #ifdefs in other places within the source file).

FYI, running the CI repeatedly is unnecessary since the CI is fairly reliable and failing legs imply something is wrong that needs to fixed. It is rare that we have some sporadic issue that gets fixed by re-running a specific leg (although that has happened from time to time).

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

Thanks, I will start working on those. I appreciate the help & advice; dupe CI was unintentional, I didn't notice you'd queued a build until after the fact.

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

For these specific failures (System.Config/Microsoft.CSharp/etc.), I would keep using IndexOf

Fixed per your advice. I have added a comment to them to act as a sentinel should we try to fix (or find) them again in the future.

if (name.IndexOf('/') >= 0) // string.Contains(char) is .NetCore2.1+ specific 
                return null; 

@ahsonkhan
Copy link
Member

ahsonkhan commented Sep 13, 2018

string.Contains(char) is .NetCore2.1+ specific

FYI: https://apisof.net/catalog/System.String.Contains(Char)

You will likely uncover several other places that won't have access to the overload (particularly for tests that are targeting netstandard).
I recommend building locally to make sure (quicker than waiting for CI). Run the following commands from the root of the repo:

build -framework=netfx // This will likely pass as is.
build-tests -skiptests -framework=netfx // Building tests is failing now.

20:17:20 IdnDnsSafeHostTest.cs(21,39): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 IdnDnsSafeHostTest.cs(22,52): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 IdnDnsSafeHostTest.cs(23,51): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 IdnDnsSafeHostTest.cs(33,39): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 IdnDnsSafeHostTest.cs(34,52): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 IdnDnsSafeHostTest.cs(35,51): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Uri/tests/FunctionalTests/System.Private.Uri.Functional.Tests.csproj]
20:17:20 Normalization.cs(172,51): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/mnt/j/workspace/dotnet_corefx/master/linux-musl-TGroup_netcoreapp+CGroup_Debug+AGroup_x64+TestOuter_false_prtest/src/System.Private.Xml/tests/Readers/FactoryReader/System.Xml.RW.FactoryReader.Tests.csproj]
20:17:20     1 Warning(s)
20:17:20     7 Error(s)
20:10:45 System\Diagnostics\RemoteExecutorTestBase.cs(311,56): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---2a8f9c29\src\CoreFx.Private.TestUtilities\src\CoreFx.Private.TestUtilities.csproj]
20:15:59 Microsoft\Win32\RegistryKey.cs(637,32): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---33cbf18b\src\Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj]
20:15:59 System\ServiceProcess\ServiceController.cs(427,73): error CS1503: Argument 1: cannot convert from 'char' to 'string' [D:\j\workspace\windows-TGrou---33cbf18b\src\System.ServiceProcess.ServiceController\src\System.ServiceProcess.ServiceController.csproj]

Hopefully these are it, but I would make sure locally first.

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

Hopefully these are it, but I would make sure locally first.

Thanks, that helped. Submitted reverts, we'll see if it passes this time around.

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

@dotnet-bot test Packaging All Configurations x64 Debug Build

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

@ahsonkhan when you have a chance, please let me know how to troubleshoot the failed test. It doesn't seem to show any errors in the console?

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

Ignore - it was hidden in plain sight, DbConnectionOptions

@@ -18,6 +18,7 @@ public void IdnDnsSafeHost_IdnOffWithBuiltInScheme_Success()

string dns = test.DnsSafeHost;

// string.Contains(char) is .NetCore2.1+ specific
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments seem even less useful for tests where we don't care about perf to this level anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous response. Do you want me to revert the comments in tests/asserts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted all comments in test/assert. Let me know if you want me to revert all comments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahsonkhan thoughts? The only reason to not revert them all is if they have using System.Linq; then I believe that Contains would compile to a slow Linq version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I believe that Contains would compile to a slow Linq version.

Imo, that's a good enough reason to keep the comment.

That Linq API is quite slow, especially due to boxing:

Method IsDataCompact TestCase Mean Error StdDev Gen 0 Allocated
StringContains True HelloWorld 2.453 ns 0.3580 ns 0.0930 ns - 0 B
LinqContains True HelloWorld 31.012 ns 2.0902 ns 0.5429 ns 0.0076 32 B

Let's make sure we aren't accidentally calling the Linq.Contains API in hot paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my cursory look, I was only able to find two possible candidates where we could use IndexOf instead (and avoid using Linq.Contains:

if (_dataSourceAfterTrimmingProtocol.Contains("/")) // Pipe paths only allow back slashes

if (!_dataSourceAfterTrimmingProtocol.Contains(BackSlashSeparator))

The ones in System.Net.WebHeaderCollection are fine since we target netcoreapp for that project:

if (isSetCookie && (!value.Contains('='))) return Array.Empty<string>();

if (!singleValue.Contains(';')) return false;

bool noComma = !lastElement.Contains(',');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another perf comparison here https://github.com/dotnet/corefx/issues/25094 where I originally added the overload. I saw 20x

Copy link
Author

@grant-d grant-d Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20x

Wow. I still have a task on my backlog to see what the per improvement is with this change. I will get to it after the units. (I doubt it will be as good as that)

Copy link
Author

@grant-d grant-d Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two possible candidates

OK, I will try update those too.
BTW, I hadn't though to look for existing callsites using the pattern .Contains("<single char>"). Your SNIProxy note made me realize that and so I have found a few more places I can change, added them to the units PR

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

The following files have using System.Linq

src/System.Net.WebHeaderCollection/src/System/Net/HeaderInfoTable.cs
src/System/Xml/Serialization/SoapReflectionImporter.cs
src/System/Xml/Serialization/XmlReflectionImporter.cs

Is there anything you want me to do about these - revert changes or otherwise?

@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

@ahsonkhan what is special about the Packaging All Configurations x64 Debug Build test. It's the only one that's failing, and it seems the build has already succeeded on Linux, OSX, NetFx, etc

@grant-d grant-d changed the title Change calls from string.IndexOf to string.Contains (CoreFX) - WIP Change calls from string.IndexOf to string.Contains (CoreFX) Sep 13, 2018
@danmoseley danmoseley merged commit 6ffca61 into dotnet:master Sep 13, 2018
@danmoseley
Copy link
Member

Thanks @grant-d

@grant-d grant-d deleted the MemContainsCalls branch September 13, 2018 22:20
@grant-d
Copy link
Author

grant-d commented Sep 13, 2018

No problem. Thanks for the help & coaching

@danmoseley
Copy link
Member

If you'd like something else, we have plenty labeled up for grabs - varying levels of accessibility
https://github.com/dotnet/corefx/issues?q=is%3Aopen+is%3Aissue+label%3Aup-for-grabs

@grant-d
Copy link
Author

grant-d commented Sep 14, 2018

Thanks, that's where I grabbed this one from. I am just adding units for this (see #32293) and then I am working on the following which was (originally) also from that query:
https://github.com/dotnet/corefx/issues/32269

@grant-d
Copy link
Author

grant-d commented Sep 14, 2018

Note that the following files have using System.Linq but we made the change to use Convert(char).
There is a risk of the Linq overload being resolved on cross-compiled platforms.

src/System.Net.WebHeaderCollection/src/System/Net/HeaderInfoTable.cs
src/System/Xml/Serialization/SoapReflectionImporter.cs
src/System/Xml/Serialization/XmlReflectionImporter.cs

HeaderInfoTable is safe per #32249 (comment) above.
I am going to undo SoapReflectionImporter.cs and XmlReflectionImporter in the Units PR for safety's sake.

@danmoseley
Copy link
Member

I assume they actually need that using System.Linq;

@grant-d
Copy link
Author

grant-d commented Sep 14, 2018

Yes, I assume so. So I have undone all changes to those 2 files (Soap/XmlReflectionImporter).
The net change is only that sentinel comment we discussed.

@karelz karelz added this to the 3.0 milestone Oct 8, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…corefx#32249)

* Update call sites

* More call sites

* Another callsite

* More call sites

* CR fixes - revert src/Common/src/CoreLib/*

* Spurious fix

* Revert string.Contains where platform may not be NetCore21

* nit

* More reverts

* More reverts

* More reverts

* Revert

* Remove comments

* Revert


Commit migrated from dotnet/corefx@6ffca61
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants