mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 17:36:14 +01:00
glib/gvarianttype: g_variant_type_is_subtype_of() fastpath
This adds a fastpath for the extremely common case of checking if a GVariant type is a subtype of itself _and_ a definite basic type. For example, checking 'i' against 'i' or 's' against 's'. In a loop using GVariantBuilder this can cut the cost of this function alone in half on profiles from 3.3% of samples to 1.7% of samples.
This commit is contained in:
parent
84b6f747cb
commit
7d4ea04ee2
@ -867,6 +867,24 @@ g_variant_type_is_subtype_of (const GVariantType *type,
|
||||
supertype_string = g_variant_type_peek_string (supertype);
|
||||
type_string = g_variant_type_peek_string (type);
|
||||
|
||||
/* fast path for the basic determinate types */
|
||||
if (type_string[0] == supertype_string[0])
|
||||
{
|
||||
switch (type_string[0])
|
||||
{
|
||||
case 'b': case 'y':
|
||||
case 'n': case 'q':
|
||||
case 'i': case 'h': case 'u':
|
||||
case 't': case 'x':
|
||||
case 's': case 'o': case 'g':
|
||||
case 'd':
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
supertype_end = supertype_string +
|
||||
g_variant_type_get_string_length (supertype);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user