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

Commit

Permalink
Reduce delegate allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Nov 4, 2015
1 parent facf3ad commit d104e8a
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
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());
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

0 comments on commit d104e8a

Please sign in to comment.