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.
This commit is contained in:
Timm Bäder 2018-07-21 10:00:35 +02:00
parent 5eba0bc932
commit c67bcf09b9
2 changed files with 60 additions and 57 deletions

View File

@ -209,89 +209,92 @@ _gtk_size_request_cache_commit (SizeRequestCache *cache,
* the Clutter toolkit but has evolved for other GTK+ requirements. * the Clutter toolkit but has evolved for other GTK+ requirements.
*/ */
gboolean gboolean
_gtk_size_request_cache_lookup (SizeRequestCache *cache, _gtk_size_request_cache_lookup (const SizeRequestCache *cache,
GtkOrientation orientation, GtkOrientation orientation,
int for_size, int for_size,
int *minimum, int *minimum,
int *natural, int *natural,
int *minimum_baseline, int *minimum_baseline,
int *natural_baseline) int *natural_baseline)
{ {
guint i, p;
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
{ {
const CachedSizeX *result = NULL;
if (for_size < 0) if (for_size < 0)
{ {
if (cache->flags[orientation].cached_size_valid) if (cache->flags[GTK_ORIENTATION_HORIZONTAL].cached_size_valid)
result = &cache->cached_size_x; {
} const CachedSizeX *result = &cache->cached_size_x;
*minimum = result->minimum_size;
*natural = result->natural_size;
return TRUE;
}
return FALSE;
}
else else
{ {
guint i;
/* Search for an already cached size */ /* 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]; const SizeRequestX *cur = cache->requests_x[i];
if (cur->lower_for_size <= for_size && if (cur->lower_for_size <= for_size &&
cur->upper_for_size >= for_size) cur->upper_for_size >= for_size)
{ {
result = &cur->cached_size; const CachedSizeX *result = &cur->cached_size;
break;
}
}
}
if (result) *minimum = result->minimum_size;
{ *natural = result->natural_size;
*minimum = result->minimum_size;
*natural = result->natural_size; return TRUE;
*minimum_baseline = -1; }
*natural_baseline = -1; }
return TRUE;
return FALSE;
} }
else
return FALSE;
} }
else else
{ {
const CachedSizeY *result = NULL;
if (for_size < 0) if (for_size < 0)
{ {
if (cache->flags[orientation].cached_size_valid) if (cache->flags[GTK_ORIENTATION_VERTICAL].cached_size_valid)
result = &cache->cached_size_y; {
} 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 else
{ {
guint i;
/* Search for an already cached size */ /* 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]; const SizeRequestY *cur = cache->requests_y[i];
if (cur->lower_for_size <= for_size && if (cur->lower_for_size <= for_size &&
cur->upper_for_size >= for_size) cur->upper_for_size >= for_size)
{ {
result = &cur->cached_size; const CachedSizeY *result = &cur->cached_size;
break;
}
}
}
if (result) *minimum = result->minimum_size;
{ *natural = result->natural_size;
*minimum = result->minimum_size; *minimum_baseline = result->minimum_baseline;
*natural = result->natural_size; *natural_baseline = result->natural_baseline;
*minimum_baseline = result->minimum_baseline; return TRUE;
*natural_baseline = result->natural_baseline; }
return TRUE; }
}
else return FALSE;
return FALSE; }
} }
} }

View File

@ -91,7 +91,7 @@ void _gtk_size_request_cache_commit (SizeRequestCach
int natural_size, int natural_size,
int minimum_baseline, int minimum_baseline,
int natural_baseline); int natural_baseline);
gboolean _gtk_size_request_cache_lookup (SizeRequestCache *cache, gboolean _gtk_size_request_cache_lookup (const SizeRequestCache *cache,
GtkOrientation orientation, GtkOrientation orientation,
int for_size, int for_size,
int *minimum, int *minimum,