From 2fcd7c22852436c3226de9007e88cb305cce1b00 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 11 Jul 2012 22:19:31 +0200 Subject: srd: Performance improvements for various PDs. Ignore/skip identical samples in most (low-level) PDs, as we're usually (but not necessarily always) only interested in pin changes. This yields a significant performance improvement for the PDs. The mechanism was already used in the 'i2s', 'jtag', and 'lpc' PDs, but not yet in all supported low-level decoders. The following PDs now also use this mechanism: 'dcf77', 'i2c', 'spi', 'uart', and 'usb_signalling'. Thanks Lars-Peter Clausen for bringing this to our attention. --- decoders/i2c/i2c.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'decoders/i2c') diff --git a/decoders/i2c/i2c.py b/decoders/i2c/i2c.py index 0e79497..53321eb 100644 --- a/decoders/i2c/i2c.py +++ b/decoders/i2c/i2c.py @@ -88,6 +88,7 @@ class Decoder(srd.Decoder): self.state = 'FIND START' self.oldscl = None self.oldsda = None + self.oldpins = None def start(self, metadata): self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2c') @@ -198,7 +199,12 @@ class Decoder(srd.Decoder): super(Decoder, self).put(self.startsample, self.samplenum, output_id, data) def decode(self, ss, es, data): - for (self.samplenum, (scl, sda)) in data: + for (self.samplenum, pins) in data: + + # Ignore identical samples early on (for performance reasons). + if self.oldpins == pins: + continue + self.oldpins, (scl, sda) = pins, pins # First sample: Save SCL/SDA value. if self.oldscl == None: -- cgit v1.2.3-70-g09d2