From patchwork Sat Jun 26 15:00:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marko Ristola X-Patchwork-Id: 108212 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5QF0M2w018327 for ; Sat, 26 Jun 2010 15:00:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752745Ab0FZPAP (ORCPT ); Sat, 26 Jun 2010 11:00:15 -0400 Received: from emh02.mail.saunalahti.fi ([62.142.5.108]:50596 "EHLO emh02.mail.saunalahti.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752478Ab0FZPAO (ORCPT ); Sat, 26 Jun 2010 11:00:14 -0400 Received: from saunalahti-vams (vs3-10.mail.saunalahti.fi [62.142.5.94]) by emh02-2.mail.saunalahti.fi (Postfix) with SMTP id C14BFEF3F7 for ; Sat, 26 Jun 2010 18:00:12 +0300 (EEST) Received: from emh01.mail.saunalahti.fi ([62.142.5.107]) by vs3-10.mail.saunalahti.fi ([62.142.5.94]) with SMTP (gateway) id A01ACDBCAC9; Sat, 26 Jun 2010 18:00:12 +0300 Received: from kuusi.koti (a88-114-153-83.elisa-laajakaista.fi [88.114.153.83]) by emh01.mail.saunalahti.fi (Postfix) with ESMTP id 9AF004033 for ; Sat, 26 Jun 2010 18:00:11 +0300 (EEST) Message-ID: <4C2615FB.2000805@kolumbus.fi> Date: Sat, 26 Jun 2010 18:00:11 +0300 From: Marko Ristola User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Thunderbird/3.0.5 MIME-Version: 1.0 To: Linux Media Mailing List Subject: [PATCH] Avoid unnecessary data copying inside dvb_dmx_swfilter_204() function X-Antivirus: VAMS Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 26 Jun 2010 15:00:24 +0000 (UTC) diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c index 977ddba..627d103 100644 --- a/drivers/media/dvb/dvb-core/dvb_demux.c +++ b/drivers/media/dvb/dvb-core/dvb_demux.c @@ -520,49 +520,60 @@ bailout: EXPORT_SYMBOL(dvb_dmx_swfilter); +static inline int find204Sync(const u8 *buf, int pos, size_t count) +{ + while(likely(pos < count)) { + if (likely(buf[pos] == 0x47 || buf[pos] == 0xB8)) + break; + pos++; + } + + return pos; +} + void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) { int p = 0, i, j; - u8 tmppack[188]; + const u8 *q; spin_lock(&demux->lock); - if (demux->tsbufp) { + if (likely(demux->tsbufp)) { /* tsbuf[0] is now 0x47. */ i = demux->tsbufp; j = 204 - i; - if (count < j) { + if (unlikely(count < j)) { memcpy(&demux->tsbuf[i], buf, count); demux->tsbufp += count; goto bailout; } memcpy(&demux->tsbuf[i], buf, j); - if ((demux->tsbuf[0] == 0x47) || (demux->tsbuf[0] == 0xB8)) { - memcpy(tmppack, demux->tsbuf, 188); - if (tmppack[0] == 0xB8) - tmppack[0] = 0x47; - dvb_dmx_swfilter_packet(demux, tmppack); - } + if (likely(demux->tsbuf[0] == 0x47)) /* double check */ + dvb_dmx_swfilter_packet(demux, demux->tsbuf); demux->tsbufp = 0; p += j; } - while (p < count) { - if ((buf[p] == 0x47) || (buf[p] == 0xB8)) { - if (count - p >= 204) { - memcpy(tmppack, &buf[p], 188); - if (tmppack[0] == 0xB8) - tmppack[0] = 0x47; - dvb_dmx_swfilter_packet(demux, tmppack); - p += 204; - } else { - i = count - p; - memcpy(demux->tsbuf, &buf[p], i); - demux->tsbufp = i; - goto bailout; - } - } else { - p++; + while (likely((p = find204Sync(buf, p, count)) < count)) { + if (unlikely(count - p < 204)) + break; + + q = &buf[p]; + + if (unlikely(*q == 0xB8)) { + memcpy(demux->tsbuf, q, 188); + demux->tsbuf[0] = 0x47; + q = demux->tsbuf; } + dvb_dmx_swfilter_packet(demux, q); + p += 204; + } + + i = count - p; + if (likely(i)) { + memcpy(demux->tsbuf, &buf[p], i); + demux->tsbufp = i; + if (unlikely(demux->tsbuf[0] == 0xB8)) + demux->tsbuf[0] = 0x47; }