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 General Public License along
18 : : * with this program. 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 : 6588160 : _g_variant_type_equal (const GVariantType *type1,
31 : : const GVariantType *type2)
32 : : {
33 : 6588160 : const char *str1 = (const char *)type1;
34 : 6588160 : const char *str2 = (const char *)type2;
35 : 6588160 : gsize index = 0;
36 : 6588160 : int brackets = 0;
37 : :
38 : 6588160 : if (str1 == str2)
39 : 32053 : return TRUE;
40 : :
41 : : do
42 : : {
43 : 9651924 : if (str1[index] != str2[index])
44 : 5161666 : return FALSE;
45 : :
46 : 4788363 : while (str1[index] == 'a' || str1[index] == 'm')
47 : : {
48 : 299111 : index++;
49 : :
50 : 299111 : if (str1[index] != str2[index])
51 : 1006 : return FALSE;
52 : : }
53 : :
54 : 4489252 : if (str1[index] == '(' || str1[index] == '{')
55 : 605448 : brackets++;
56 : :
57 : 3883804 : else if (str1[index] == ')' || str1[index] == '}')
58 : 595167 : brackets--;
59 : :
60 : 4489252 : index++;
61 : : }
62 : 4489252 : while (brackets);
63 : :
64 : 1393435 : return TRUE;
65 : : }
66 : :
67 : : static inline guint
68 : 630413 : _g_variant_type_hash (gconstpointer type)
69 : : {
70 : 630413 : const gchar *type_string = type;
71 : 630413 : guint value = 0;
72 : 630413 : gsize index = 0;
73 : 630413 : int brackets = 0;
74 : :
75 : : do
76 : : {
77 : 6996963 : value = (value << 5) - value + type_string[index];
78 : :
79 : 7473093 : while (type_string[index] == 'a' || type_string[index] == 'm')
80 : : {
81 : 476130 : index++;
82 : :
83 : 476130 : value = (value << 5) - value + type_string[index];
84 : : }
85 : :
86 : 6996963 : if (type_string[index] == '(' || type_string[index] == '{')
87 : 784675 : brackets++;
88 : :
89 : 6212288 : else if (type_string[index] == ')' || type_string[index] == '}')
90 : 784675 : brackets--;
91 : :
92 : 6996963 : index++;
93 : : }
94 : 6996963 : while (brackets);
95 : :
96 : 630413 : return value;
97 : : }
98 : :
99 : : G_END_DECLS
|