Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 85762c2

Browse files
author
Cesar Blum Silveira
committed
Avoid unecessary allocation for RawTarget.
1 parent f7e50e8 commit 85762c2

File tree

4 files changed

+69
-18
lines changed

4 files changed

+69
-18
lines changed

KestrelHttpServer.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server
3232
EndProject
3333
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.FunctionalTests", "test\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests\Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.xproj", "{9559A5F1-080C-4909-B6CF-7E4B3DC55748}"
3434
EndProject
35+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Http", "..\HttpAbstractions\src\Microsoft.AspNetCore.Http\Microsoft.AspNetCore.Http.xproj", "{BCF0F967-8753-4438-BD07-AADCA9CE509A}"
36+
EndProject
37+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Http.Abstractions", "..\HttpAbstractions\src\Microsoft.AspNetCore.Http.Abstractions\Microsoft.AspNetCore.Http.Abstractions.xproj", "{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}"
38+
EndProject
39+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Http.Extensions", "..\HttpAbstractions\src\Microsoft.AspNetCore.Http.Extensions\Microsoft.AspNetCore.Http.Extensions.xproj", "{CCC4363E-81E2-4058-94DD-00494E9E992A}"
40+
EndProject
41+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Http.Features", "..\HttpAbstractions\src\Microsoft.AspNetCore.Http.Features\Microsoft.AspNetCore.Http.Features.xproj", "{D9128247-8F97-48B8-A863-F1F21A029FCE}"
42+
EndProject
43+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.WebUtilities", "..\HttpAbstractions\src\Microsoft.AspNetCore.WebUtilities\Microsoft.AspNetCore.WebUtilities.xproj", "{A2FB7838-0031-4FAD-BA3E-83C30B3AF406}"
44+
EndProject
45+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Net.Http.Headers", "..\HttpAbstractions\src\Microsoft.Net.Http.Headers\Microsoft.Net.Http.Headers.xproj", "{60AA2FDB-8121-4826-8D00-9A143FEFAF66}"
46+
EndProject
3547
Global
3648
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3749
Debug|Any CPU = Debug|Any CPU
@@ -66,6 +78,30 @@ Global
6678
{9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = Debug|Any CPU
6779
{9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.ActiveCfg = Release|Any CPU
6880
{9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = Release|Any CPU
81+
{BCF0F967-8753-4438-BD07-AADCA9CE509A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82+
{BCF0F967-8753-4438-BD07-AADCA9CE509A}.Debug|Any CPU.Build.0 = Debug|Any CPU
83+
{BCF0F967-8753-4438-BD07-AADCA9CE509A}.Release|Any CPU.ActiveCfg = Release|Any CPU
84+
{BCF0F967-8753-4438-BD07-AADCA9CE509A}.Release|Any CPU.Build.0 = Release|Any CPU
85+
{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
86+
{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
87+
{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
88+
{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}.Release|Any CPU.Build.0 = Release|Any CPU
89+
{CCC4363E-81E2-4058-94DD-00494E9E992A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
90+
{CCC4363E-81E2-4058-94DD-00494E9E992A}.Debug|Any CPU.Build.0 = Debug|Any CPU
91+
{CCC4363E-81E2-4058-94DD-00494E9E992A}.Release|Any CPU.ActiveCfg = Release|Any CPU
92+
{CCC4363E-81E2-4058-94DD-00494E9E992A}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{D9128247-8F97-48B8-A863-F1F21A029FCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
94+
{D9128247-8F97-48B8-A863-F1F21A029FCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
95+
{D9128247-8F97-48B8-A863-F1F21A029FCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
96+
{D9128247-8F97-48B8-A863-F1F21A029FCE}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{A2FB7838-0031-4FAD-BA3E-83C30B3AF406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{A2FB7838-0031-4FAD-BA3E-83C30B3AF406}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{A2FB7838-0031-4FAD-BA3E-83C30B3AF406}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{A2FB7838-0031-4FAD-BA3E-83C30B3AF406}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Any CPU.Build.0 = Release|Any CPU
69105
EndGlobalSection
70106
GlobalSection(SolutionProperties) = preSolution
71107
HideSolutionNode = FALSE

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"projects": ["src"]
2+
"projects": ["src","D:/src/aspnet/HttpAbstractions/src"]
33
}

src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
837837
queryString = begin.GetAsciiString(scan);
838838
}
839839

840-
var rawTarget = pathBegin.GetAsciiString(scan);
840+
var queryEnd = scan;
841841

842842
if (pathBegin.Peek() == ' ')
843843
{
@@ -886,8 +886,12 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
886886
// Multibyte Internationalized Resource Identifiers (IRIs) are first converted to utf8;
887887
// then encoded/escaped to ASCII https://www.ietf.org/rfc/rfc3987.txt "Mapping of IRIs to URIs"
888888
string requestUrlPath;
889+
string rawTarget;
889890
if (needDecode)
890891
{
892+
// Read raw target before mutating memory.
893+
rawTarget = pathBegin.GetAsciiString(queryEnd);
894+
891895
// URI was encoded, unescape and then parse as utf8
892896
pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd);
893897
requestUrlPath = pathBegin.GetUtf8String(pathEnd);
@@ -897,6 +901,17 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
897901
{
898902
// URI wasn't encoded, parse as ASCII
899903
requestUrlPath = pathBegin.GetAsciiString(pathEnd);
904+
905+
if (queryString.Length == 0)
906+
{
907+
// No need to allocate an extra string if the path didn't need
908+
// decoding and there's no query string following it.
909+
rawTarget = requestUrlPath;
910+
}
911+
else
912+
{
913+
rawTarget = pathBegin.GetAsciiString(queryEnd);
914+
}
900915
}
901916

902917
requestUrlPath = PathNormalizer.RemoveDotSegments(requestUrlPath);

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/project.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
"xunit": "2.1.0"
1212
},
1313
"frameworks": {
14-
"netcoreapp1.0": {
15-
"dependencies": {
16-
"Microsoft.NETCore.App": {
17-
"version": "1.0.0-*",
18-
"type": "platform"
19-
},
20-
"System.Net.Http": "4.0.1-*",
21-
"System.Net.Http.WinHttpHandler": "4.0.0-*",
22-
"System.Runtime.Serialization.Primitives": "4.1.1-*"
23-
},
24-
"imports": [
25-
"portable-dnxcore50+net45+win8+wp8+wpa81",
26-
"dotnet",
27-
"portable-net45+win8"
28-
]
29-
},
14+
//"netcoreapp1.0": {
15+
// "dependencies": {
16+
// "Microsoft.NETCore.App": {
17+
// "version": "1.0.0-*",
18+
// "type": "platform"
19+
// },
20+
// "System.Net.Http": "4.0.1-*",
21+
// "System.Net.Http.WinHttpHandler": "4.0.0-*",
22+
// "System.Runtime.Serialization.Primitives": "4.1.1-*"
23+
// },
24+
// "imports": [
25+
// "portable-dnxcore50+net45+win8+wp8+wpa81",
26+
// "dotnet",
27+
// "portable-net45+win8"
28+
// ]
29+
//},
3030
"net451": {
3131
"dependencies": {
3232
"xunit.runner.console": "2.1.0"

0 commit comments

Comments
 (0)