cssnumbervalue: Add early-outs to transition code
authorTimm Bäder <mail@baedert.org>
Wed, 8 Jan 2020 08:42:23 +0000 (09:42 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 18 Jan 2020 07:49:51 +0000 (08:49 +0100)
we don't need to do the calculation at all if the progress is 0 or 1
anyway.

We also sometimes transition from 0 to 0 etc., so we can short-circuit
that as well by doing the fast pointer-equality check and relying on the
singletons.

gtk/gtkcssnumbervalue.c

index f5e574c81d0a85201e2eb0d52895828d4eef4ef6..83fa257f01eca4b7dc194b72c4af9b40a1750f06 100644 (file)
@@ -115,6 +115,15 @@ gtk_css_number_value_transition (GtkCssValue *start,
 {
   GtkCssValue *result, *mul_start, *mul_end;
 
+  if (progress == 0)
+    return _gtk_css_value_ref (start);
+
+  if (progress == 1)
+    return _gtk_css_value_ref (end);
+
+  if (start == end)
+    return _gtk_css_value_ref (start);
+
   mul_start = gtk_css_number_value_multiply (start, 1 - progress);
   mul_end = gtk_css_number_value_multiply (end, progress);