[vala/0.48] vala: Use stable hash for methods in HashMap of implicit_implementations



commit 32963645e74255363a460636cbee5dec6e5a6cb8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu May 7 20:58:36 2020 +0200

    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 586fe287f..9d71a4239 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -116,7 +116,7 @@ public class Vala.Class : ObjectTypeSymbol {
        private bool? _is_singleton;
 
        private List<DataType> base_types = new ArrayList<DataType> ();
-       private HashMap<Method,Method> implicit_implementations = new HashMap<Method,Method> ();
+       private HashMap<Method,Method> implicit_implementations = new HashMap<Method,Method> 
(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) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]