From: "Kirill A. Shutsemov" <kirill@shutemov.name> To: "Dmitry V. Levin" <ldv@altlinux.org>, Alexey Tourbin <at@altlinux.ru> Cc: "Alexey I. Froloff" <raorn@altlinux.org>, devel@lists.altlinux.org, Alexey Gladkov <legion@altlinux.ru>, "Kirill A. Shutemov" <kirill@shutemov.name> Subject: [devel] [PATCH 3/3] set.c: optimize decode_golomb() Date: Fri, 26 Nov 2010 00:04:26 +0200 Message-ID: <1290722666-24606-4-git-send-email-kirill@shutemov.name> (raw) In-Reply-To: <1290722666-24606-1-git-send-email-kirill@shutemov.name> From: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> --- 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
next prev parent reply other threads:[~2010-11-25 22:04 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-11-25 22:04 [devel] [PATCH 0/3] optimize rpmsetcmp() Kirill A. Shutsemov 2010-11-25 22:04 ` [devel] [PATCH 1/3] set.c: use packed bitmap for bit vector Kirill A. Shutsemov 2010-11-25 22:04 ` [devel] [PATCH 2/3] set.c: optimize putbits() Kirill A. Shutsemov 2010-11-25 22:04 ` Kirill A. Shutsemov [this message] 2010-11-26 8:35 ` [devel] [PATCH 0/3] optimize rpmsetcmp() Kirill A. Shutemov 2010-11-30 0:35 ` Dmitry V. Levin 2010-12-02 21:48 ` Dmitry V. Levin 2010-12-04 13:02 ` Alexey Tourbin 2010-12-04 16:30 ` Dmitry V. Levin 2010-12-04 16:55 ` Alexey Tourbin 2010-12-04 15:06 ` Alexey Tourbin 2010-12-04 16:29 ` Dmitry V. Levin 2010-12-04 16:42 ` Alexey Tourbin 2010-12-04 16:52 ` Dmitry V. Levin 2010-12-04 17:05 ` Alexey Tourbin 2010-12-04 17:52 ` Dmitry V. Levin 2010-12-04 21:28 ` Alexey Tourbin 2010-12-04 23:26 ` Dmitry V. Levin 2010-12-04 23:41 ` Alexey Tourbin 2010-12-05 0:03 ` Dmitry V. Levin 2010-12-05 0:21 ` Alexey Tourbin 2010-12-05 12:49 ` Michael Shigorin 2010-12-07 17:50 ` Dmitry V. Levin 2010-12-05 1:24 ` Alexey Tourbin 2010-12-05 11:18 ` Dmitry V. Levin 2010-12-05 12:39 ` Alexey Tourbin 2010-12-05 12:39 ` Michael Shigorin 2010-12-05 12:58 ` Alexey Tourbin 2010-12-05 15:27 ` Dmitry V. Levin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1290722666-24606-4-git-send-email-kirill@shutemov.name \ --to=kirill@shutemov.name \ --cc=at@altlinux.ru \ --cc=devel@lists.altlinux.org \ --cc=ldv@altlinux.org \ --cc=legion@altlinux.ru \ --cc=raorn@altlinux.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
ALT Linux Team development discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \ devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru public-inbox-index devel Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.devel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git