]> xenbits.xensource.com Git - libvirt.git/commitdiff
apibuild: Simplify type checking of literals
authorRadostin Stoyanov <rstoyanov1@gmail.com>
Tue, 20 Mar 2018 06:49:03 +0000 (06:49 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 20 Mar 2018 12:13:36 +0000 (12:13 +0000)
Reduce the number of if-statements used to assign a literals
to corresponding class variables.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
docs/apibuild.py

index 06d556baea6c02c7821e098951a1722b3a4a5c9f..f073b36c7e9ddff157fe542ebfd88f0c0b131e06 100755 (executable)
@@ -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)