Repository: dotnet/roslyn
File: src/Compilers/Core/MSBuildTask/ManagedCompiler.cs (C#)

Code before:

            // On Windows, no transformation is needed
            if (Path.DirectorySeparatorChar == '\\')
                return null;

            // Go over sources once and lazily initialize transformedSources if needed
            string[]? transformedSources = null;
            for (int i = 0; i < sources.Length; i++)
            {
                var itemSpec = sources[i].ItemSpec;
                // Check if this path needs transformation using the compiler's heuristic:
                // A path starting with '/' is treated as an option unless it contains 
                // another '/' after the first character (e.g., "/dir/file.cs" is safe)
                if (itemSpec.Length > 1 && itemSpec[0] == '/' && itemSpec.IndexOf('/', 1) < 0)
                {
                    // Lazy initialization: create the array on first transformation
                    if (transformedSources == null)
                    {
                        transformedSources = new string[sources.Length];
                        // Copy all items processed so far
                        for (int j = 0; j < i; j++)
                        {
                            transformedSources[j] = sources[j].ItemSpec;
                        }
                    }
                    // Transform this path to prevent misinterpretation as an option
                    transformedSources[i] = "/." + itemSpec;
                }
                else if (transformedSources != null)
                {
                    // If we've already started transforming, copy this item as-is
                    transformedSources[i] = itemSpec;
                }
            }

            return transformedSources;
        }

        /// <summary>
        /// Whether the command line compiler was invoked, instead
        /// of the host object compiler.
        /// </summary>
        protected bool UsedCommandLineTool
        {
            get;
            set;
        }

        private bool _hostCompilerSupportsAllParameters;
        protected bool HostCompilerSupportsAllParameters
        {

Review comment (suggestion):
```suggestion
                        sources.AsSpan(0, j).CopyTo(transformedSources.AsSpan());
```

Code after:
                return null;

            // On Windows, no transformation is needed
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                return null;

            // Go over sources once and lazily initialize transformedSources if needed
            string[]? transformedSources = null;
            for (int i = 0; i < sources.Length; i++)
            {
                var itemSpec = sources[i].ItemSpec;

                // Check if this path needs transformation using the compiler's heuristic:
                // A path starting with '/' is treated as an option unless it contains 
                // another '/' after the first character (e.g., "/dir/file.cs" is safe)
                if (itemSpec.Length > 1 && itemSpec[0] == '/' && itemSpec.IndexOf('/', 1) < 0)
                {
                    // Lazy initialization: create the array on first transformation
                    if (transformedSources == null)
                    {
                        transformedSources = new string[sources.Length];
                        // Copy all items processed so far
                        for (int j = 0; j < i; j++)
                        {
                            transformedSources[j] = sources[j].ItemSpec;
                        }
                    }

                    // Transform this path to prevent misinterpretation as an option
                    transformedSources[i] = "/." + itemSpec;
                }
                else if (transformedSources != null)
                {
                    // If we've already started transforming, copy this item as-is
                    transformedSources[i] = itemSpec;
                }
            }

            return transformedSources;
        }

        /// <summary>
        /// Whether the command line compiler was invoked, instead
        /// of the host object compiler.
        /// </summary>
        protected bool UsedCommandLineTool
        {
            get;
            set;
        }