Optimize for the common case that packet.c received exactly one full packet
authorVolker Lendecke <vl@samba.org>
Sat, 20 Dec 2008 09:51:54 +0000 (10:51 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 2 Jan 2009 21:11:50 +0000 (22:11 +0100)
source3/lib/packet.c

index 72de30e8ca8920f213f2527cd49332819eac90b5..ef28bf9f625b53b0f8ef214eaf1e0ac3fe9262d4 100644 (file)
@@ -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;