From c67bcf09b9f06f50be62f9bb7c43674fa289887b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 21 Jul 2018 10:00:35 +0200 Subject: [PATCH] sizerequestcache: Inline out-var assignments The additional assignment to the old result variable just adds an indirection even though we know the point where we assign it in all cases. Just pass the values out and return in those cases instead. --- gtk/gtksizerequestcache.c | 115 ++++++++++++++++--------------- gtk/gtksizerequestcacheprivate.h | 2 +- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/gtk/gtksizerequestcache.c b/gtk/gtksizerequestcache.c index 52d8421cc9..a68e29903f 100644 --- a/gtk/gtksizerequestcache.c +++ b/gtk/gtksizerequestcache.c @@ -209,89 +209,92 @@ _gtk_size_request_cache_commit (SizeRequestCache *cache, * the Clutter toolkit but has evolved for other GTK+ requirements. */ gboolean -_gtk_size_request_cache_lookup (SizeRequestCache *cache, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) +_gtk_size_request_cache_lookup (const SizeRequestCache *cache, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) { + guint i, p; + if (orientation == GTK_ORIENTATION_HORIZONTAL) { - const CachedSizeX *result = NULL; - if (for_size < 0) - { - if (cache->flags[orientation].cached_size_valid) - result = &cache->cached_size_x; - } + { + if (cache->flags[GTK_ORIENTATION_HORIZONTAL].cached_size_valid) + { + const CachedSizeX *result = &cache->cached_size_x; + + *minimum = result->minimum_size; + *natural = result->natural_size; + return TRUE; + } + + return FALSE; + } else { - guint i; - /* Search for an already cached size */ - for (i = 0; i < cache->flags[orientation].n_cached_requests; i++) - { + for (i = 0, p = cache->flags[GTK_ORIENTATION_HORIZONTAL].n_cached_requests; i < p; i++) + { const SizeRequestX *cur = cache->requests_x[i]; if (cur->lower_for_size <= for_size && cur->upper_for_size >= for_size) { - result = &cur->cached_size; - break; - } - } - } + const CachedSizeX *result = &cur->cached_size; - if (result) - { - *minimum = result->minimum_size; - *natural = result->natural_size; - *minimum_baseline = -1; - *natural_baseline = -1; - return TRUE; + *minimum = result->minimum_size; + *natural = result->natural_size; + + return TRUE; + } + } + + return FALSE; } - else - return FALSE; } else { - const CachedSizeY *result = NULL; - if (for_size < 0) - { - if (cache->flags[orientation].cached_size_valid) - result = &cache->cached_size_y; - } + { + if (cache->flags[GTK_ORIENTATION_VERTICAL].cached_size_valid) + { + const CachedSizeY *result = &cache->cached_size_y; + + *minimum = result->minimum_size; + *natural = result->natural_size; + *minimum_baseline = result->minimum_baseline; + *natural_baseline = result->natural_baseline; + return TRUE; + } + + return FALSE; + } else { - guint i; - /* Search for an already cached size */ - for (i = 0; i < cache->flags[orientation].n_cached_requests; i++) - { + for (i = 0, p = cache->flags[GTK_ORIENTATION_VERTICAL].n_cached_requests; i < p; i++) + { const SizeRequestY *cur = cache->requests_y[i]; if (cur->lower_for_size <= for_size && cur->upper_for_size >= for_size) { - result = &cur->cached_size; - break; - } - } - } + const CachedSizeY *result = &cur->cached_size; - if (result) - { - *minimum = result->minimum_size; - *natural = result->natural_size; - *minimum_baseline = result->minimum_baseline; - *natural_baseline = result->natural_baseline; - return TRUE; - } - else - return FALSE; + *minimum = result->minimum_size; + *natural = result->natural_size; + *minimum_baseline = result->minimum_baseline; + *natural_baseline = result->natural_baseline; + return TRUE; + } + } + + return FALSE; + } } } diff --git a/gtk/gtksizerequestcacheprivate.h b/gtk/gtksizerequestcacheprivate.h index ee826f4bb3..62ff226031 100644 --- a/gtk/gtksizerequestcacheprivate.h +++ b/gtk/gtksizerequestcacheprivate.h @@ -91,7 +91,7 @@ void _gtk_size_request_cache_commit (SizeRequestCach int natural_size, int minimum_baseline, int natural_baseline); -gboolean _gtk_size_request_cache_lookup (SizeRequestCache *cache, +gboolean _gtk_size_request_cache_lookup (const SizeRequestCache *cache, GtkOrientation orientation, int for_size, int *minimum,