[virt-tools-list] [libvirt] [PATCH 19/22] apibuild: Simplify type checking of literals

Radostin Stoyanov rstoyanov1 at gmail.com
Sat Mar 17 13:48:55 UTC 2018


Reduce the number of if-statements used to assign a literals
to corresponding class variables.

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 docs/apibuild.py | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index fd1ee7958..29c89fd24 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -283,24 +283,19 @@ class index:
             d.set_static(1)
 
         if d is not None and name is not None and type is not None:
-            if type == "function":
-                self.functions[name] = d
-            elif type == "functype":
-                self.functions[name] = d
-            elif type == "variable":
-                self.variables[name] = d
-            elif type == "include":
-                self.includes[name] = d
-            elif type == "struct":
-                self.structs[name] = d
-            elif type == "union":
-                self.unions[name] = d
-            elif type == "enum":
-                self.enums[name] = d
-            elif type == "typedef":
-                self.typedefs[name] = d
-            elif type == "macro":
-                self.macros[name] = d
+            type_map = {
+                "function": self.functions,
+                "functype": self.functions,
+                "variable": self.variables,
+                "include": self.includes,
+                "struct": self.structs,
+                "union": self.unions,
+                "enum": self.enums,
+                "typedef": self.typedefs,
+                "macro": self.macros
+            }
+            if type in type_map:
+                type_map[type][name] = d
             else:
                 self.warning("Unable to register type ", type)
 
-- 
2.14.3




More information about the virt-tools-list mailing list