From: Rico Tzschichholz Date: Thu, 7 May 2020 18:58:36 +0000 (+0200) Subject: vala: Use stable hash for methods in HashMap of implicit_implementations X-Git-Tag: 0.46.10~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=424e7e60eb63e29102306d1810dd95ed7357df52;p=thirdparty%2Fvala.git vala: Use stable hash for methods in HashMap of implicit_implementations Fixes https://gitlab.gnome.org/GNOME/vala/issues/990 --- diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 5824ef822..2ebcdb49f 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -110,7 +110,7 @@ public class Vala.Class : ObjectTypeSymbol { private bool? _is_singleton; private List base_types = new ArrayList (); - private HashMap implicit_implementations = new HashMap (); + private HashMap implicit_implementations = new HashMap (Symbol.hash_func, Symbol.equal_func); /** * Specifies the default construction method. diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala index 790ddd9b9..6b1c7f665 100644 --- a/vala/valasymbol.vala +++ b/vala/valasymbol.vala @@ -321,6 +321,27 @@ public abstract class Vala.Symbol : CodeNode { return result_builder.str; } + /** + * Implementation of GLib.EqualFunc to use with e.g. HashMap + * + * @param a a symbol + * @param b a symbol + * @return whether the given instances represent the same symbol + */ + public static bool equal_func (Symbol a, Symbol b) { + return str_equal (a.get_full_name (), b.get_full_name ()); + } + + /** + * Implementation of GLib.HashFunc to use with e.g. HashMap + * + * @param s a symbol + * @return a hash value + */ + public static uint hash_func (Symbol s) { + return str_hash (s.get_full_name ()); + } + // get the top scope from where this symbol is still accessible public Scope? get_top_accessible_scope (bool is_internal = false) { if (access == SymbolAccessibility.PRIVATE) {