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

Reduce delegate allocation #321

Merged
merged 1 commit into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.Server.Kestrel/Http/MessageBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Primitives;
using System.IO;

namespace Microsoft.AspNet.Server.Kestrel.Http
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public static bool TryGet(IDictionary<string, StringValues> headers, string name
value = values[0];
return true;
}
value = String.Join(",", values);
value = string.Join(",", values.ToArray());
Copy link
Member

Choose a reason for hiding this comment

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

Before this change wasn't this overload of string.Join being used? Is there a reason to avoid that overload?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, boxes enumerator to IEnumerator; as items > 1 we know .ToArray will return an underlying array without creation.

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Server.Kestrel/Http/PipeListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override UvStreamHandle CreateListenSocket()
var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(ServerAddress.UnixPipePath);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this);
return socket;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override UvStreamHandle CreateListenSocket()
var socket = new UvPipeHandle(Log);
socket.Init(Thread.Loop, false);
socket.Bind(ServerAddress.UnixPipePath);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this);
return socket;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Server.Kestrel/Http/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override UvStreamHandle CreateListenSocket()
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.NoDelay(NoDelay);
socket.Bind(ServerAddress);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this);
return socket;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override UvStreamHandle CreateListenSocket()
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
socket.NoDelay(NoDelay);
socket.Bind(ServerAddress);
socket.Listen(Constants.ListenBacklog, ConnectionCallback, this);
socket.Listen(Constants.ListenBacklog, (stream, status, error, state) => ConnectionCallback(stream, status, error, state), this);
return socket;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public class UvAsyncHandle : UvHandle
{
private static Libuv.uv_async_cb _uv_async_cb = AsyncCb;
private static Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle);
private Action _callback;

public UvAsyncHandle(IKestrelTrace logger) : base(logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
/// </summary>
public class UvConnectRequest : UvRequest
{
private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb;
private readonly static Libuv.uv_connect_cb _uv_connect_cb = (req, status) => UvConnectCb(req, status);

private Action<UvConnectRequest, int, Exception, object> _callback;
private object _state;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public abstract class UvHandle : UvMemory
{
private static Libuv.uv_close_cb _destroyMemory = DestroyMemory;
private static Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle);
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;

protected UvHandle(IKestrelTrace logger) : base (logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{
public abstract class UvStreamHandle : UvHandle
{
private readonly static Libuv.uv_connection_cb _uv_connection_cb = UvConnectionCb;
private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = UvAllocCb;
private readonly static Libuv.uv_read_cb _uv_read_cb = UvReadCb;
private readonly static Libuv.uv_connection_cb _uv_connection_cb = (handle, status) => UvConnectionCb(handle, status);
// Ref and out lamda params must be explicitly typed
private readonly static Libuv.uv_alloc_cb _uv_alloc_cb = (IntPtr handle, int suggested_size, out Libuv.uv_buf_t buf) => UvAllocCb(handle, suggested_size, out buf);
private readonly static Libuv.uv_read_cb _uv_read_cb = (IntPtr handle, int status, ref Libuv.uv_buf_t buf) => UvReadCb(handle, status, ref buf);

public Action<UvStreamHandle, int, Exception, object> _listenCallback;
public object _listenState;
Expand Down