From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on sa.int.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 From: "Kirill A. Shutsemov" To: "Dmitry V. Levin" , Alexey Tourbin Date: Fri, 26 Nov 2010 00:04:26 +0200 Message-Id: <1290722666-24606-4-git-send-email-kirill@shutemov.name> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1290722666-24606-1-git-send-email-kirill@shutemov.name> References: <1290722666-24606-1-git-send-email-kirill@shutemov.name> Cc: "Alexey I. Froloff" , devel@lists.altlinux.org, Alexey Gladkov , "Kirill A. Shutemov" Subject: [devel] [PATCH 3/3] set.c: optimize decode_golomb() X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 22:04:41 -0000 Archived-At: List-Archive: List-Post: From: Kirill A. Shutemov Signed-off-by: Kirill A. Shutemov --- lib/set.c | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/set.c b/lib/set.c index 02a6c31..8a425b7 100644 --- a/lib/set.c +++ b/lib/set.c @@ -396,16 +396,16 @@ int decode_golomb(int bitc, const unsigned long *bitmap, int Mshift, unsigned *v int offset = 0; /* next value */ - while (bitc > 0) { + while (offset < bitc) { unsigned q, r; char bit; - int i; + int quot, rem; + int k; /* first part */ q = 0; bit = 0; - while (bitc > 0) { - bitc--; + while (offset < bitc) { bit = get_bit(bitmap, offset++); if (bit == 0) q++; @@ -414,20 +414,22 @@ int decode_golomb(int bitc, const unsigned long *bitmap, int Mshift, unsigned *v } /* trailing zero bits in the input are okay */ - if (bitc == 0 && bit == 0) + if (offset == bitc && bit == 0) break; /* otherwise, incomplete value is not okay */ - if (bitc < Mshift) + if (bitc - offset < Mshift) return -1; + quot = offset / BITS_PER_LONG; + rem = offset % BITS_PER_LONG; + k = rem + Mshift - BITS_PER_LONG; + /* second part */ - r = 0; - for (i = 0; i < Mshift; i++) { - bitc--; - if (get_bit(bitmap, offset++)) - r |= BIT(i); - } + r = (bitmap[quot] & (MASK(Mshift) << rem)) >> rem; + if (k > 0) + r |= (bitmap[quot + 1] & MASK(k)) << (Mshift - k); + offset += Mshift; /* the value */ *v++ = (q << Mshift) | r; -- 1.7.3.2