Branch data Line data Source code
1 : : /* gvarianttype-private.h
2 : : *
3 : : * Copyright © 2007, 2008 Ryan Lortie
4 : : * Copyright © 2009, 2010 Codethink Limited
5 : : * Copyright © 2024 Christian Hergert
6 : : *
7 : : * This library is free software; you can redistribute it and/or modify
8 : : * it under the terms of the GNU Lesser General Public License as
9 : : * published by the Free Software Foundation; either version 2.1 of the
10 : : * License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful, but
13 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General Public
18 : : * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 : : *
20 : : * SPDX-License-Identifier: LGPL-2.1-or-later
21 : : */
22 : :
23 : : #pragma once
24 : :
25 : : #include "gvarianttype.h"
26 : :
27 : : G_BEGIN_DECLS
28 : :
29 : : static inline gboolean
30 : 7281217 : _g_variant_type_equal (const GVariantType *type1,
31 : : const GVariantType *type2)
32 : : {
33 : 7281217 : const char *str1 = (const char *)type1;
34 : 7281217 : const char *str2 = (const char *)type2;
35 : 7281217 : gsize index = 0;
36 : 7281217 : int brackets = 0;
37 : :
38 : 7281217 : if (str1 == str2)
39 : 35081 : return TRUE;
40 : :
41 : : do
42 : : {
43 : 10430137 : if (str1[index] != str2[index])
44 : 5725080 : return FALSE;
45 : :
46 : 4973075 : while (str1[index] == 'a' || str1[index] == 'm')
47 : : {
48 : 269064 : index++;
49 : :
50 : 269064 : if (str1[index] != str2[index])
51 : 1046 : return FALSE;
52 : : }
53 : :
54 : 4704011 : if (str1[index] == '(' || str1[index] == '{')
55 : 708890 : brackets++;
56 : :
57 : 3995121 : else if (str1[index] == ')' || str1[index] == '}')
58 : 698085 : brackets--;
59 : :
60 : 4704011 : index++;
61 : : }
62 : 4704011 : while (brackets);
63 : :
64 : 1520010 : return TRUE;
65 : : }
66 : :
67 : : static inline guint
68 : 691619 : _g_variant_type_hash (gconstpointer type)
69 : : {
70 : 691619 : const gchar *type_string = type;
71 : 691619 : guint value = 0;
72 : 691619 : gsize index = 0;
73 : 691619 : int brackets = 0;
74 : :
75 : : do
76 : : {
77 : 7497074 : value = (value << 5) - value + type_string[index];
78 : :
79 : 7962262 : while (type_string[index] == 'a' || type_string[index] == 'm')
80 : : {
81 : 465188 : index++;
82 : :
83 : 465188 : value = (value << 5) - value + type_string[index];
84 : : }
85 : :
86 : 7497074 : if (type_string[index] == '(' || type_string[index] == '{')
87 : 912358 : brackets++;
88 : :
89 : 6584716 : else if (type_string[index] == ')' || type_string[index] == '}')
90 : 912358 : brackets--;
91 : :
92 : 7497074 : index++;
93 : : }
94 : 7497074 : while (brackets);
95 : :
96 : 691619 : return value;
97 : : }
98 : :
99 : : G_END_DECLS
|