From patchwork Thu Jun 4 13:41:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 480745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D2F8F1401AF for ; Thu, 4 Jun 2015 23:56:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=U0EyC5Hd; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id A0FB728C0CF; Thu, 4 Jun 2015 15:52:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 3348528C0A9 for ; Thu, 4 Jun 2015 15:52:00 +0200 (CEST) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 4 Jun 2015 15:51:56 +0200 (CEST) Received: by padjw17 with SMTP id jw17so30184263pad.2 for ; Thu, 04 Jun 2015 06:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2OUVZsVhqbAa0/erlU2OucHDDd6P7ixJUNjCWAwmf5I=; b=U0EyC5HdVjnVaP4TnjbhOlOZNWSdjo13+ZBf9XYxKDEKslALiwAYshAR82/XA0E6JQ Gna9j2Rqq2ljiIxorh0i0HEx/xS8ls8NAi2beGJjJssKAjDFDpdXkRWeVDLb9OsA5QJl nEBIxa5X9MnIJc3iApkRpuf2WQgN4euRgB12OwV/SMxHp02BsFMRZjYge2NcKKUfhP+X t0kXkk91wwGjxZ5m8r8k8SzH9nmV1VjqzhJo9gpVP7ewyUMl1O+jDGMSpoO01uSyuyxa llk/LSV6XHOOatzHNhalyBahNB3eeVnl72OGRVfRmxIyFSMYeG5XboLnpeEyVJTeeMIB 7QOQ== X-Received: by 10.66.250.131 with SMTP id zc3mr57249859pac.136.1433426010157; Thu, 04 Jun 2015 06:53:30 -0700 (PDT) Received: from debian.corp.sankuai.com ([103.29.140.58]) by mx.google.com with ESMTPSA id qt4sm3885676pbc.86.2015.06.04.06.53.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2015 06:53:29 -0700 (PDT) From: Yousong Zhou To: nbd@openwrt.org Date: Thu, 4 Jun 2015 21:41:40 +0800 Message-Id: <1433425302-26448-4-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1433425302-26448-1-git-send-email-yszhou4tech@gmail.com> References: <1433425302-26448-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH 3/5] ustream: tweak ustream_prepare_buf() a bit. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" No functional change. - Reuse existing NULL check on buf. - Add some comments for ease of reading the code. Signed-off-by: Yousong Zhou --- ustream.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ustream.c b/ustream.c index fc93bc2..e7ee9f0 100644 --- a/ustream.c +++ b/ustream.c @@ -145,21 +145,26 @@ static bool ustream_should_move(struct ustream_buf_list *l, struct ustream_buf * int maxlen; int offset; + /* nothing to squeeze */ if (buf->data == buf->head) return false; maxlen = buf->end - buf->head; offset = buf->data - buf->head; + /* less than half is available */ if (offset > maxlen / 2) return true; + /* less than 32 bytes data but takes more than 1/4 space */ if (buf->tail - buf->data < 32 && offset > maxlen / 4) return true; + /* more buf is already in list or can be allocated */ if (buf != l->tail || ustream_can_alloc(l)) return false; + /* no need to move if len is available at the tail */ return (buf->end - buf->tail < len); } @@ -255,13 +260,14 @@ static bool ustream_prepare_buf(struct ustream *s, struct ustream_buf_list *l, i if (l == &s->r) ustream_fixup_string(s, buf); } + /* some chunks available at the tail */ if (buf->tail != buf->end) return true; - } - - if (buf && buf->next) { - l->data_tail = buf->next; - return true; + /* next buf available */ + if (buf->next) { + l->data_tail = buf->next; + return true; + } } if (!ustream_can_alloc(l))