This repository was archived by the owner on Nov 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Introduce StringValues to replace string[] usage. #378
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.Framework.Primitives; | ||
|
||
namespace SampleApp | ||
{ | ||
public class Program | ||
{ | ||
public void Main(string[] args) | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
Stopwatch timer = new Stopwatch(); | ||
timer.Start(); | ||
string myString; | ||
string[] myArray; | ||
StringValues myValues; | ||
for (int j = 0; j < 100000000; j++) | ||
{ | ||
myString = new string('a', 40); | ||
myArray = new[] { myString }; | ||
// myValues = new StringValues(myString); | ||
myValues = new StringValues(myArray); | ||
} | ||
timer.Stop(); | ||
Console.WriteLine(timer.Elapsed + ", " + Environment.WorkingSet); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>1d0764b4-1deb-4232-a714-d4b7e846918a</ProjectGuid> | ||
<RootNamespace>SampleApp</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
|
||
"dependencies": { | ||
"Microsoft.AspNet.Http": "1.0.0-*" | ||
}, | ||
|
||
"commands": { | ||
"SampleApp": "SampleApp" | ||
}, | ||
|
||
"frameworks": { | ||
"dnx451": { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not run on .NET Core 5.0? |
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.Http.Internal; | ||
using Microsoft.Framework.Primitives; | ||
|
||
namespace Microsoft.AspNet.Http | ||
{ | ||
public static class HeaderDictionaryExtensions | ||
{ | ||
/// <summary> | ||
/// Add new values. Each item remains a separate array entry. | ||
/// </summary> | ||
/// <param name="key">The header name.</param> | ||
/// <param name="value">The header value.</param> | ||
public static void Append(this IHeaderDictionary headers, string key, StringValues value) | ||
{ | ||
ParsingHelpers.AppendHeaderUnmodified(headers, key, value); | ||
} | ||
|
||
/// <summary> | ||
/// Quotes any values containing comas, and then coma joins all of the values with any existing values. | ||
/// </summary> | ||
/// <param name="key">The header name.</param> | ||
/// <param name="values">The header values.</param> | ||
public static void AppendCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values) | ||
{ | ||
ParsingHelpers.AppendHeaderJoined(headers, key, values); | ||
} | ||
|
||
/// <summary> | ||
/// Get the associated values from the collection separated into individual values. | ||
/// Quoted values will not be split, and the quotes will be removed. | ||
/// </summary> | ||
/// <param name="key">The header name.</param> | ||
/// <returns>the associated values from the collection separated into individual values, or StringValues.Empty if the key is not present.</returns> | ||
public static string[] GetCommaSeparatedValues(this IHeaderDictionary headers, string key) | ||
{ | ||
return ParsingHelpers.GetHeaderSplit(headers, key); | ||
} | ||
|
||
/// <summary> | ||
/// Quotes any values containing comas, and then coma joins all of the values. | ||
/// </summary> | ||
/// <param name="key">The header name.</param> | ||
/// <param name="values">The header values.</param> | ||
public static void SetCommaSeparatedValues(this IHeaderDictionary headers, string key, params string[] values) | ||
{ | ||
ParsingHelpers.SetHeaderJoined(headers, key, values); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??