diff runtime/internal/genobj.d @ 1512:09734fb929c0

Make == for associative arrays test for equality, not identity. _aaEq was added to runtime/internal/aaA.d which forwards to TypeInfo_AssociativeArray.equals in genobj.d. On the codegen side, DtoAAEquals was added to gen/aa.cpp and is called from EqualExp::toElem in gen/toir.cpp. I assume that the frontend will produce an error if == is used on associative arrays of different type. This fixes DMD bug 1429.
author Christian Kamm <kamm incasoftware de>
date Sun, 21 Jun 2009 19:05:24 +0200
parents 0a5f7890f327
children
line wrap: on
line diff
--- a/runtime/internal/genobj.d	Sun Jun 21 00:12:29 2009 +0200
+++ b/runtime/internal/genobj.d	Sun Jun 21 19:05:24 2009 +0200
@@ -47,6 +47,8 @@
     import util.string;
     import tango.stdc.stdio;  // : printf, snprintf;
     import tango.core.Version;
+    
+    import aaA;
 
     extern (C) void onOutOfMemoryError();
     extern (C) Object _d_allocclass(ClassInfo ci);
@@ -555,6 +557,29 @@
     }
 
     // BUG: need to add the rest of the functions
+    
+    int equals(void *p1, void *p2)
+    {
+        AA aa = *cast(AA*)p1;
+        AA ab = *cast(AA*)p2;
+        
+        if (_aaLen(aa) != _aaLen(ab))
+            return 0;
+        
+        int equal = 1;
+        int eq_x(void* k, void* va)
+        {
+            void* vb = _aaIn(ab, key, k);
+            if (!vb || !value.equals(va, vb))
+            {
+                equal = 0;
+                return 1; // break
+            }
+            return 0;
+        }
+        _aaApply2(aa, key.tsize(), &eq_x);
+        return equal;
+    }
 
     size_t tsize()
     {