Python: Use range instead of xrange.
authorUwe Hermann <uwe@hermann-uwe.de>
Sun, 18 Apr 2010 00:02:35 +0000 (02:02 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Sun, 18 Apr 2010 00:02:35 +0000 (02:02 +0200)
For small numbers range seems to be faster, and xramge is being removed
anyway in Python 3 AFAIK.

scripts/transitioncounter.py

index 05a07e378435062bcae05234296f1e659c465e4e..7c9c6a3e3d05bef37be6a57f399226968c034e4d 100644 (file)
@@ -40,7 +40,7 @@ def sigrokdecode_count_transitions(inbuf):
 
        # Presets...
        oldbyte = inbuf[0]
 
        # Presets...
        oldbyte = inbuf[0]
-       for i in xrange(channels):
+       for i in range(channels):
                oldbit[i] = (oldbyte & (1 << i)) != 0
 
        # Loop over all samples.
                oldbit[i] = (oldbyte & (1 << i)) != 0
 
        # Loop over all samples.
@@ -49,7 +49,7 @@ def sigrokdecode_count_transitions(inbuf):
                # Optimization: Skip identical bytes (no transitions).
                if oldbyte == s:
                        continue
                # Optimization: Skip identical bytes (no transitions).
                if oldbyte == s:
                        continue
-               for i in xrange(channels):
+               for i in range(channels):
                        curbit = (s & (1 << i) != 0)
                        # Optimization: Skip identical bits (no transitions).
                        if oldbit[i] == curbit:
                        curbit = (s & (1 << i) != 0)
                        # Optimization: Skip identical bits (no transitions).
                        if oldbit[i] == curbit:
@@ -61,17 +61,17 @@ def sigrokdecode_count_transitions(inbuf):
                        oldbit[i] = curbit
 
        # Total number of transitions is the sum of rising and falling edges.
                        oldbit[i] = curbit
 
        # Total number of transitions is the sum of rising and falling edges.
-       for i in xrange(channels):
+       for i in range(channels):
                transitions[i] = rising[i] + falling[i]
 
        outbuf += "Rising edges:  "
                transitions[i] = rising[i] + falling[i]
 
        outbuf += "Rising edges:  "
-       for i in xrange(channels):
+       for i in range(channels):
                outbuf += str(rising[i]) + " "
        outbuf += "\nFalling edges: "
                outbuf += str(rising[i]) + " "
        outbuf += "\nFalling edges: "
-       for i in xrange(channels):
+       for i in range(channels):
                outbuf += str(falling[i]) + " "
        outbuf += "\nTransitions:   "
                outbuf += str(falling[i]) + " "
        outbuf += "\nTransitions:   "
-       for i in xrange(channels):
+       for i in range(channels):
                outbuf += str(transitions[i]) + " "
        outbuf += "\n"
 
                outbuf += str(transitions[i]) + " "
        outbuf += "\n"