From 2135f8806c5154bb55374faf83cdecb48d4de090 Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Mon, 8 Aug 2011 05:23:00 +0000
Subject: [PATCH] use sets rather then tuples for if checks, python optimizes
 this case.

---
 io_export_directx_x.py          |  6 ++---
 io_import_scene_dxf.py          |  2 +-
 io_mesh_ply/import_ply.py       |  2 +-
 io_scene_3ds/import_3ds.py      |  2 +-
 io_scene_fbx/export_fbx.py      |  2 +-
 io_scene_x3d/export_x3d.py      |  2 +-
 object_grease_scatter.py        | 40 ++++++++++++++++-----------------
 render_povray/render.py         |  6 ++---
 render_renderfarmfi.py          |  4 ++--
 rigify/__init__.py              |  2 +-
 rigify/ui.py                    |  2 +-
 space_view3d_copy_attributes.py |  2 +-
 space_view3d_math_vis/utils.py  |  2 +-
 space_view3d_spacebar_menu.py   |  2 +-
 14 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/io_export_directx_x.py b/io_export_directx_x.py
index 056111b26..76a60d425 100644
--- a/io_export_directx_x.py
+++ b/io_export_directx_x.py
@@ -107,11 +107,11 @@ def ExportDirectX(Config):
         print("Generating Object list for export... (Root parents only)")
     if Config.ExportMode == 1:
         Config.ExportList = [Object for Object in Config.context.scene.objects
-                             if Object.type in ("ARMATURE", "EMPTY", "MESH")
+                             if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}
                              and Object.parent is None]
     else:
         ExportList = [Object for Object in Config.context.selected_objects
-                      if Object.type in ("ARMATURE", "EMPTY", "MESH")]
+                      if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
         Config.ExportList = [Object for Object in ExportList
                              if Object.parent not in ExportList]
     if Config.Verbose:
@@ -184,7 +184,7 @@ def ExportDirectX(Config):
 
 def GetObjectChildren(Parent):
     return [Object for Object in Parent.children
-            if Object.type in ("ARMATURE", "EMPTY", "MESH")]
+            if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
 
 #Returns the vertex count of Mesh, counting each vertex for every face.
 def GetMeshVertexCount(Mesh):
diff --git a/io_import_scene_dxf.py b/io_import_scene_dxf.py
index 0c7abd20d..72bc967ed 100644
--- a/io_import_scene_dxf.py
+++ b/io_import_scene_dxf.py
@@ -2247,7 +2247,7 @@ def buildGeometry(entities):
     f_faces = []
     f_vn = 0
     for ent in entities:
-        if ent.drawtype in ('Mesh','Curve'):
+        if ent.drawtype in {'Mesh', 'Curve'}:
             (verts, edges, faces, vn) = ent.build()
             if not toggle & T_DrawOne:
                 drawGeometry(verts, edges, faces)
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index 6d4326e47..e2e730b66 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -235,7 +235,7 @@ def load_ply(filepath):
             if -1 in colindices:
                 colindices = None
             else:  # if not a float assume uchar
-                colmultiply = [1.0 if el.properties[i].numeric_type in ('f', 'd') else (1.0 / 256.0) for i in colindices]
+                colmultiply = [1.0 if el.properties[i].numeric_type in {'f', 'd'} else (1.0 / 256.0) for i in colindices]
 
         elif el.name == b'face':
             findex = el.index(b'vertex_indices')
diff --git a/io_scene_3ds/import_3ds.py b/io_scene_3ds/import_3ds.py
index 209fc4041..f39fe0e5e 100644
--- a/io_scene_3ds/import_3ds.py
+++ b/io_scene_3ds/import_3ds.py
@@ -214,7 +214,7 @@ def skip_to_end(file, skip_chunk):
 def add_texture_to_material(image, texture, material, mapto):
     #print('assigning %s to %s' % (texture, material))
 
-    if mapto not in ("COLOR", "SPECULARITY", "ALPHA", "NORMAL"):
+    if mapto not in {'COLOR', 'SPECULARITY', 'ALPHA', 'NORMAL'}:
         print('/tError:  Cannot map to "%s"\n\tassuming diffuse color. modify material "%s" later.' % (mapto, material.name))
         mapto = "COLOR"
 
diff --git a/io_scene_fbx/export_fbx.py b/io_scene_fbx/export_fbx.py
index 67422691b..90555e100 100644
--- a/io_scene_fbx/export_fbx.py
+++ b/io_scene_fbx/export_fbx.py
@@ -972,7 +972,7 @@ def save_single(operator, scene, filepath="",
         if light_type > 2:
             light_type = 1  # hemi and area lights become directional
 
-        if light.type in ('HEMI', ):
+        if light.type == 'HEMI':
             do_light = not (light.use_diffuse or light.use_specular)
             do_shadow = False
         else:
diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py
index f1635f178..8d61d43df 100644
--- a/io_scene_x3d/export_x3d.py
+++ b/io_scene_x3d/export_x3d.py
@@ -1254,7 +1254,7 @@ def export(file,
 
             if obj_type == 'CAMERA':
                 writeViewpoint(ident, obj, obj_matrix, scene)
-            elif obj_type in ('MESH', 'CURVE', 'SURF', 'FONT'):
+            elif obj_type in {'MESH', 'CURVE', 'SURF', 'FONT'}:
                 if (obj_type != 'MESH') or (use_apply_modifiers and obj.is_modified(scene, 'PREVIEW')):
                     try:
                         me = obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
diff --git a/object_grease_scatter.py b/object_grease_scatter.py
index 139ca7a8e..8746a12cc 100644
--- a/object_grease_scatter.py
+++ b/object_grease_scatter.py
@@ -26,13 +26,14 @@ bl_info = {
     "version": (0, 1),
     "blender": (2, 5, 8),
     "api": 36079,
-    "location": "File > Export > Cameras & Markers (.py)",
-    "description": "Export Cameras & Markers (.py)",
+    "location": "3D View, Toolbar",
+    "description": ("Scatter a group of objects onto the active mesh using "
+                    "the grease pencil lines"),
     "warning": "",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
-        "Scripts/Object/Grease_Scatter",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
-        "func=detail&aid=TODO",
+    "wiki_url": ("http://wiki.blender.org/index.php/Extensions:2.5/Py/"
+                 "Scripts/Object/Grease_Scatter"),
+    "tracker_url": ("https://projects.blender.org/tracker/index.php?"
+                    "func=detail&aid=TODO"),
     "support": 'OFFICIAL',
     "category": "Object"}
 
@@ -115,20 +116,19 @@ def _main(self, DENSITY=1.0, SCALE=0.6, RAND_LOC=0.8, RAND_ALIGN=0.75):
         scene.objects.link(obj_new)
 
     ray = o.ray_cast
+    closest_point = o.closest_point_on_mesh
     #ray = C.scene.ray_cast
 
     DEBUG = False
 
     def fix_point(p):
-        for d in dirs:
-            # print(p)
-            hit, no, ind = ray(p, p + d)
-            if ind != -1:
-                if DEBUG:
-                    return [p, no, None]
-                else:
-                    # print("good", hit, no)
-                    return [hit, no, None]
+        hit, no, ind = closest_point(p)
+        if ind != -1:
+            if DEBUG:
+                return [p, no, None]
+            else:
+                # print("good", hit, no)
+                return [hit, no, None]
 
         # worry!
         print("bad!", p, BAD_NORMAL)
@@ -373,11 +373,11 @@ class Scatter(bpy.types.Operator):
                     pass
 
         _main(self,
-            DENSITY=self.properties.density,
-            SCALE=self.properties.scale,
-            RAND_LOC=self.properties.rand_loc,
-            RAND_ALIGN=self.properties.rand_align
-        )
+              DENSITY=self.properties.density,
+              SCALE=self.properties.scale,
+              RAND_LOC=self.properties.rand_loc,
+              RAND_ALIGN=self.properties.rand_align,
+              )
         return {'FINISHED'}
 
     def invoke(self, context, event):
diff --git a/render_povray/render.py b/render_povray/render.py
index 6cdc21937..6260a0771 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -645,7 +645,7 @@ def write_pov(filename, scene=None, info_callback=None):
 
             # Sun shouldn't be attenuated. Hemi and area lights have no falloff attribute so they
             # are put to type 2 attenuation a little higher above.
-            if lamp.type not in ('SUN', 'AREA', 'HEMI'):
+            if lamp.type not in {'SUN', 'AREA', 'HEMI'}:
                 tabWrite("fade_distance %.6f\n" % (lamp.distance / 5.0))
                 if lamp.falloff_type == 'INVERSE_SQUARE':
                     tabWrite("fade_power %d\n" % 2)  # Use blenders lamp quad equivalent
@@ -682,7 +682,7 @@ def write_pov(filename, scene=None, info_callback=None):
             meta = ob.data
 
             # important because no elements will break parsing.
-            elements = [elem for elem in meta.elements if elem.type in ('BALL', 'ELLIPSOID')]
+            elements = [elem for elem in meta.elements if elem.type in {'BALL', 'ELLIPSOID'}]
 
             if elements:
                 tabWrite("blob {\n")
@@ -839,7 +839,7 @@ def write_pov(filename, scene=None, info_callback=None):
 
             # XXX I moved all those checks here, as there is no need to compute names
             #     for object we won’t export here!
-            if ob.type in ('LAMP', 'CAMERA', 'EMPTY', 'META', 'ARMATURE', 'LATTICE'):
+            if ob.type in {'LAMP', 'CAMERA', 'EMPTY', 'META', 'ARMATURE', 'LATTICE'}:
                 continue
 
             try:
diff --git a/render_renderfarmfi.py b/render_renderfarmfi.py
index 01656c591..862aa1071 100644
--- a/render_renderfarmfi.py
+++ b/render_renderfarmfi.py
@@ -565,7 +565,7 @@ def checkStatus(ore):
     if ore.hash=='' and (ore.username=='' or ore.password==''):
         bpy.errors.append('missing_creds')
     
-    if '' in (ore.title, ore.longdesc, ore.shortdesc):
+    if '' in {ore.title, ore.longdesc, ore.shortdesc}:
         bpy.errors.append('missing_desc')
     
     setStatus('username', ore.hash=='' and ore.username=='')
@@ -604,7 +604,7 @@ def xmlSessionsToOreSessions(sessions, queue):
         s = completed[sid]['title']
         # t = completed[sid]['timestamps']  # UNUSED
         sinfo = OreSession(sid, s) 
-        if queue in ('completed', 'active'):
+        if queue in {'completed', 'active'}:
             sinfo.frames = completed[sid]['framesRendered']
         sinfo.startframe = completed[sid]['startFrame']
         sinfo.endframe = completed[sid]['endFrame']
diff --git a/rigify/__init__.py b/rigify/__init__.py
index c7b02d6c1..4884abac5 100644
--- a/rigify/__init__.py
+++ b/rigify/__init__.py
@@ -56,7 +56,7 @@ def get_rig_list(path):
 
     for f in files:
         is_dir = os.path.isdir(os.path.join(SEARCH_DIR_ABS, f))  # Whether the file is a directory
-        if f[0] in (".", "_"):
+        if f[0] in {".", "_"}:
             pass
         elif f.count(".") >= 2 or (is_dir and "." in f):
             print("Warning: %r, filename contains a '.', skipping" % os.path.join(SEARCH_DIR_ABS, f))
diff --git a/rigify/ui.py b/rigify/ui.py
index 7551ce86d..741d6dab3 100644
--- a/rigify/ui.py
+++ b/rigify/ui.py
@@ -46,7 +46,7 @@ class DATA_PT_rigify_buttons(bpy.types.Panel):
         obj = context.object
         id_store = C.window_manager
 
-        if obj.mode in ('POSE', 'OBJECT'):
+        if obj.mode in {'POSE', 'OBJECT'}:
             row = layout.row()
             row.operator("pose.rigify_generate", text="Generate")
         elif obj.mode == 'EDIT':
diff --git a/space_view3d_copy_attributes.py b/space_view3d_copy_attributes.py
index a6ffc08bd..307b9b702 100644
--- a/space_view3d_copy_attributes.py
+++ b/space_view3d_copy_attributes.py
@@ -743,7 +743,7 @@ class MESH_OT_CopyFaceSettings(bpy.types.Operator):
                     to_face.use_twoside = from_face.use_twoside
                 elif mode == 'TRANSP':
                     to_face.blend_type = from_face.blend_type
-                elif mode in ('UV', 'IMAGE'):
+                elif mode in {'UV', 'IMAGE'}:
                     attr = mode.lower()
                     setattr(to_face, attr, getattr(from_face, attr))
         return _end({'FINISHED'})
diff --git a/space_view3d_math_vis/utils.py b/space_view3d_math_vis/utils.py
index 08a2427f1..4fbc724ef 100644
--- a/space_view3d_math_vis/utils.py
+++ b/space_view3d_math_vis/utils.py
@@ -52,7 +52,7 @@ def console_math_data():
             data_quat[key] = var
         elif var_type is Euler:
             data_euler[key] = var
-        elif var_type in (list, tuple):
+        elif var_type in {list, tuple}:
             if var:
                 ok = True
                 for item in var:
diff --git a/space_view3d_spacebar_menu.py b/space_view3d_spacebar_menu.py
index 33a029cc2..4583e4228 100644
--- a/space_view3d_spacebar_menu.py
+++ b/space_view3d_spacebar_menu.py
@@ -698,7 +698,7 @@ class VIEW3D_MT_Space_Dynamic_Menu(bpy.types.Menu):
             layout.separator()
 
 
-            if arm.draw_type in ('BBONE', 'ENVELOPE'):
+            if arm.draw_type in {'BBONE', 'ENVELOPE'}:
                 layout.operator("transform.transform",
                     text="Scale Envelope Distance").mode = 'BONE_SIZE'
 
-- 
GitLab