From 424e7e60eb63e29102306d1810dd95ed7357df52 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Thu, 7 May 2020 20:58:36 +0200 Subject: [PATCH] vala: Use stable hash for methods in HashMap of implicit_implementations Fixes https://gitlab.gnome.org/GNOME/vala/issues/990 --- vala/valaclass.vala | 2 +- vala/valasymbol.vala | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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) { -- 2.47.2