mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-02-14 19:03:14 +01:00
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.
This commit is contained in:
@@ -705,6 +705,11 @@ body
|
||||
}
|
||||
|
||||
|
||||
int _aaEq(AA aa, AA ab, TypeInfo_AssociativeArray ti)
|
||||
{
|
||||
return ti.equals(&aa, &ab);
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* Construct an associative array of type ti from
|
||||
* length pairs of key/value pairs.
|
||||
|
||||
@@ -47,6 +47,8 @@ private
|
||||
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 @@ class TypeInfo_AssociativeArray : TypeInfo
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user