Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -4653,17 +4653,33 @@ public import core.internal.switch_: __switch_error;
public @trusted @nogc nothrow pure extern (C) void _d_delThrowable(scope Throwable);

// Compare class and interface objects for ordering.
private int __cmp(Obj)(Obj lhs, Obj rhs)
if (is(Obj : Object))
int __cmp(C1, C2)(C1 lhs, C2 rhs)
if ((is(C1 : const(Object)) || (is(C1 == interface) && (__traits(getLinkage, C1) == "D"))) &&
(is(C2 : const(Object)) || (is(C2 == interface) && (__traits(getLinkage, C2) == "D"))))
{
if (lhs is rhs)
static if (is(C1 == typeof(null)) && is(C2 == typeof(null)))
{
return 0;
// Regard null references as always being "less than"
if (!lhs)
}
else static if (is(C1 == typeof(null)))
{
// Regard null references as always being "less than"
return -1;
if (!rhs)
}
else static if (is(C2 == typeof(null)))
{
return 1;
return lhs.opCmp(rhs);
}
else
{
if (lhs is rhs)
return 0;
if (lhs is null)
return -1;
if (rhs is null)
return 1;
return lhs.opCmp(rhs);
}
}

// objects
Expand Down