Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 51187200D34 for ; Fri, 3 Nov 2017 07:38:34 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4F936160BFB; Fri, 3 Nov 2017 06:38:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BF0E9160BE9 for ; Fri, 3 Nov 2017 07:38:33 +0100 (CET) Received: (qmail 2898 invoked by uid 500); 3 Nov 2017 06:38:32 -0000 Mailing-List: contact dev-help@orc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@orc.apache.org Delivered-To: mailing list dev@orc.apache.org Received: (qmail 2887 invoked by uid 99); 3 Nov 2017 06:38:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Nov 2017 06:38:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5A0F9DFBD7; Fri, 3 Nov 2017 06:38:32 +0000 (UTC) From: t3rmin4t0r To: dev@orc.apache.org Reply-To: dev@orc.apache.org References: In-Reply-To: Subject: [GitHub] orc pull request #186: ORC-187: BitFieldReader has an unnecessary loop Content-Type: text/plain Message-Id: <20171103063832.5A0F9DFBD7@git1-us-west.apache.org> Date: Fri, 3 Nov 2017 06:38:32 +0000 (UTC) archived-at: Fri, 03 Nov 2017 06:38:34 -0000 Github user t3rmin4t0r commented on a diff in the pull request: https://github.com/apache/orc/pull/186#discussion_r148716091 --- Diff: java/core/src/java/org/apache/orc/impl/BitFieldReader.java --- @@ -162,53 +92,32 @@ public void seek(PositionProvider index) throws IOException { consumed + " in " + input); } else if (consumed != 0) { readByte(); - bitsLeft = 8 - consumed; + currentIdx = (byte) consumed; } else { - bitsLeft = 0; + currentIdx = 8; } } public void skip(long items) throws IOException { - long totalBits = bitSize * items; - if (bitsLeft >= totalBits) { - bitsLeft -= totalBits; + final long totalBits = bitSize * items; + final int availableBits = 8 - (currentIdx + 1); + if (totalBits <= availableBits) { + currentIdx += totalBits; } else { - totalBits -= bitsLeft; - input.skip(totalBits / 8); - current = input.next(); - bitsLeft = (int) (8 - (totalBits % 8)); + final long bitsToSkip = (totalBits - availableBits); + input.skip(Math.min(1, bitsToSkip / 8)); --- End diff -- Looks a bit odd - the min(1) might be a problem if availableBits = 0 and items=3, it will end up skip(1) where it should really be doing skip(0). ---