Components: small optimization- change find to in
authorTaapat <taapat@gmail.com>
Sat, 26 Oct 2013 19:10:20 +0000 (22:10 +0300)
committerMirakels <mirakels@openpli.org>
Sun, 27 Oct 2013 14:22:23 +0000 (15:22 +0100)
Mirakels: small optimizations and additional changelog.
'a.find(string)' is much slower than 'string in a'.
So if not interested in the position of string within 'a', the 'in'
construct is better.

Signed-off-by: Mirakels <mirakels@openpli.org>

lib/python/Components/AVSwitch.py
lib/python/Components/Converter/ConfigEntryTest.py
lib/python/Components/InputDevice.py
lib/python/Components/ScrollLabel.py
lib/python/Components/ServiceScan.py
lib/python/enigma_py_patcher.py

index f4e561c..0db2f9f 100644 (file)
@@ -147,7 +147,7 @@ def InitAVSwitch():
        SystemInfo["ScartSwitch"] = eAVSwitch.getInstance().haveScartSwitch()
 
        try:
-               can_downmix = open("/proc/stb/audio/ac3_choices", "r").read()[:-1].find("downmix") != -1
+               can_downmix = "downmix" in open("/proc/stb/audio/ac3_choices", "r").read()
        except:
                can_downmix = False
 
index 166e6be..127141e 100644 (file)
@@ -15,7 +15,7 @@ class ConfigEntryTest(Converter, object):
                if len(args) < 2:
                        self.argerror = True
                else:
-                       if args[0].find("config.") != -1:
+                       if "config." in args[0]:
                                self.configKey = args[0]
                                self.configValue = args[1]
                                if len(args) > 2:
index 0227ac0..1c3cfd9 100644 (file)
@@ -47,11 +47,11 @@ class inputDevices:
 
 
        def getInputDeviceType(self,name):
-               if name.find("remote control") != -1:
+               if "remote control" in name:
                        return "remote"
-               elif name.find("keyboard") != -1:
+               elif "keyboard" in name:
                        return "keyboard"
-               elif name.find("mouse") != -1:
+               elif "mouse" in name:
                        return "mouse"
                else:
                        print "Unknown device type:",name
index 3fa2294..6a0189c 100644 (file)
@@ -20,9 +20,9 @@ class ScrollLabel(HTMLComponent, GUIComponent):
                        widget_attribs = [ ]
                        scrollbar_attribs = [ ]
                        for (attrib, value) in self.skinAttributes:
-                               if attrib.find("borderColor") != -1 or attrib.find("borderWidth") != -1:
+                               if "borderColor" in attrib or "borderWidth" in attrib:
                                        scrollbar_attribs.append((attrib,value))
-                               if attrib.find("transparent") != -1 or attrib.find("backgroundColor") != -1:
+                               if "transparent" in attrib or "backgroundColor" in attrib:
                                        widget_attribs.append((attrib,value))
                        skin.applyAllAttributes(self.instance, desktop, widget_attribs, parent.scale)
                        skin.applyAllAttributes(self.scrollbar, desktop, scrollbar_attribs+widget_attribs, parent.scale)
index 7441e21..13fd3f7 100644 (file)
@@ -57,7 +57,7 @@ class ServiceScan:
                                                        h = _("W")
                                                else:
                                                        h = _("E")
-                                               if sat_name.find("%d.%d" % (orb_pos/10, orb_pos%10)) != -1:
+                                               if ("%d.%d" % (orb_pos/10, orb_pos%10)) in sat_name:
                                                        network = sat_name
                                                else:
                                                        network = ("%s %d.%d %s") % (sat_name, orb_pos / 10, orb_pos % 10, h)
index 309ca41..0a93bfc 100644 (file)
@@ -18,7 +18,7 @@ for line, str in enumerate(source):
                while spacepos > 0 and str[spacepos] != ' ':
                        spacepos -= 1
                tmpstr = str[spacepos:pos]
-               if tmpstr.find('_enigma.') == -1:
+               if '_enigma.' not in tmpstr:
                        str = str[:pos]+str[pos+6:]
 
        if oldstr != str: