summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Bridon <mathieu@hashbang.fr>2019-07-23 15:32:53 +0200
committerMathieu Bridon <mathieu@hashbang.fr>2019-07-23 15:32:53 +0200
commita7149a0ba83921591fe309a9cde0f8e43b55739c (patch)
tree5d987d879e5e3bc67466c5454f164039c33bcd38
parentcf435d614f6a60892fd915a5a2868b6b33d18168 (diff)
downloadpygobject-a7149a0ba83921591fe309a9cde0f8e43b55739c.tar.gz
variant: Get the type string only once when unpacking
This saves a bit of work. Unpacking many GVariants in a loop, this shaved roughly 6% of the total time.
-rw-r--r--gi/overrides/GLib.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 186902e8..a383f583 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -236,19 +236,21 @@ class Variant(GLib.Variant):
'g': self.get_string, # signature
}
+ type_string = self.get_type_string()
+
# simple values
- la = LEAF_ACCESSORS.get(self.get_type_string())
+ la = LEAF_ACCESSORS.get(type_string)
if la:
return la()
# tuple
- if self.get_type_string().startswith('('):
+ if type_string.startswith('('):
res = [self.get_child_value(i).unpack()
for i in range(self.n_children())]
return tuple(res)
# dictionary
- if self.get_type_string().startswith('a{'):
+ if type_string.startswith('a{'):
res = {}
for i in range(self.n_children()):
v = self.get_child_value(i)
@@ -256,21 +258,21 @@ class Variant(GLib.Variant):
return res
# array
- if self.get_type_string().startswith('a'):
+ if type_string.startswith('a'):
return [self.get_child_value(i).unpack()
for i in range(self.n_children())]
# variant (just unbox transparently)
- if self.get_type_string().startswith('v'):
+ if type_string.startswith('v'):
return self.get_variant().unpack()
# maybe
- if self.get_type_string().startswith('m'):
+ if type_string.startswith('m'):
if not self.n_children():
return None
return self.get_child_value(0).unpack()
- raise NotImplementedError('unsupported GVariant type ' + self.get_type_string())
+ raise NotImplementedError('unsupported GVariant type ' + type_string)
@classmethod
def split_signature(klass, signature):