Skip to content

Commit a1d0249

Browse files
author
Kuzko Sergii
committed
refactoring
1 parent 72eac87 commit a1d0249

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

druntime/src/core/internal/array/equality.d

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ bool __equals(T1, T2)(scope T1[] lhs, scope T2[] rhs) @trusted
2323
return true;
2424

2525
alias PureType = bool function(scope T1[], scope T2[], size_t) @safe pure nothrow @nogc;
26-
2726
return (cast(PureType)&isEqual!(T1,T2))(lhs, rhs, lhs.length);
2827
}
2928

@@ -49,25 +48,39 @@ bool __equals(T1, T2, size_t N, size_t M)(scope ref T1[N] lhs, scope ref T2[M] r
4948
private
5049
bool isEqual(T1, T2)(scope T1[] lhs, scope T2[] rhs, size_t length)
5150
{
52-
// Returns a reference to an array element, eliding bounds check and
53-
// casting void to ubyte.
54-
pragma(inline, true)
55-
static ref at(T)(scope T[] r, size_t i) @trusted
56-
// exclude opaque structs due to https://issues.dlang.org/show_bug.cgi?id=20959
57-
if (!(is(T == struct) && !is(typeof(T.sizeof))))
51+
static if (is(T1 == T2) &&
52+
(__traits(isIntegral, T1) || is(T1 == char) || is(T1 == wchar) ||
53+
is(T1 == dchar) || is(T1 == bool) || is(T1 == class)))
5854
{
59-
static if (is(T == void))
60-
return (cast(ubyte[]) r)[i];
61-
else
62-
return r[i];
55+
foreach (i; 0 .. length)
56+
{
57+
if (lhs.ptr[i] != rhs.ptr[i])
58+
return false;
59+
}
60+
return true;
6361
}
64-
65-
foreach (const i; 0 .. length)
62+
else
6663
{
67-
if (at(lhs, i) != at(rhs, i))
68-
return false;
64+
// Returns a reference to an array element, eliding bounds check and
65+
// casting void to ubyte.
66+
pragma(inline, true)
67+
static ref at(T)(scope T[] r, size_t i) @trusted
68+
// exclude opaque structs due to https://issues.dlang.org/show_bug.cgi?id=20959
69+
if (!(is(T == struct) && !is(typeof(T.sizeof))))
70+
{
71+
static if (is(T == void))
72+
return (cast(ubyte[]) r)[i];
73+
else
74+
return r[i];
75+
}
76+
77+
foreach (const i; 0 .. length)
78+
{
79+
if (at(lhs, i) != at(rhs, i))
80+
return false;
81+
}
82+
return true;
6983
}
70-
return true;
7184
}
7285

7386
@safe unittest

0 commit comments

Comments
 (0)