From b4e1eb4345ab0be00e31d09cf0753597ef0af44a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 20 Dec 2008 10:51:54 +0100 Subject: Optimize for the common case that packet.c received exactly one full packet --- source3/lib/packet.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source3/lib/packet.c b/source3/lib/packet.c index 72de30e8ca..ef28bf9f62 100644 --- a/source3/lib/packet.c +++ b/source3/lib/packet.c @@ -140,15 +140,21 @@ bool packet_handler(struct packet_context *ctx, return true; } - buf = (uint8_t *)TALLOC_MEMDUP(ctx, ctx->in.data, length); - if (buf == NULL) { - *status = NT_STATUS_NO_MEMORY; - return true; - } + if (length == ctx->in.length) { + buf = ctx->in.data; + ctx->in.data = NULL; + ctx->in.length = 0; + } else { + buf = (uint8_t *)TALLOC_MEMDUP(ctx, ctx->in.data, length); + if (buf == NULL) { + *status = NT_STATUS_NO_MEMORY; + return true; + } - memmove(ctx->in.data, ctx->in.data + length, - ctx->in.length - length); - ctx->in.length -= length; + memmove(ctx->in.data, ctx->in.data + length, + ctx->in.length - length); + ctx->in.length -= length; + } *status = callback(buf, length, priv); return True; -- cgit