Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Refactor TypeInfo_Array #2506

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 1 addition & 25 deletions src/rt/typeinfo/ti_Acdouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,5 @@ private import rt.util.typeinfo;

class TypeInfo_Ar : TypeInfo_Array
{
alias F = cdouble;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!cdouble;
}
26 changes: 1 addition & 25 deletions src/rt/typeinfo/ti_Acfloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,5 @@ private import rt.util.typeinfo;

class TypeInfo_Aq : TypeInfo_Array
{
alias F = cfloat;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!cfloat;
}
26 changes: 1 addition & 25 deletions src/rt/typeinfo/ti_Acreal.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,5 @@ private import rt.util.typeinfo;

class TypeInfo_Ac : TypeInfo_Array
{
alias F = creal;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!creal;
}
35 changes: 2 additions & 33 deletions src/rt/typeinfo/ti_Adouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,12 @@ private import rt.util.typeinfo;

class TypeInfo_Ad : TypeInfo_Array
{
alias F = double;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!double;
}

// idouble[]

class TypeInfo_Ap : TypeInfo_Ad
{
alias F = idouble;

override string toString() const { return (F[]).stringof; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!idouble;
}
35 changes: 2 additions & 33 deletions src/rt/typeinfo/ti_Afloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,12 @@ private import rt.util.typeinfo;

class TypeInfo_Af : TypeInfo_Array
{
alias F = float;

override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return (F[]).stringof; }

override size_t getHash(scope const void* p) @trusted const
{
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

override int compare(in void* p1, in void* p2) const
{
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!float;
}

// ifloat[]
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved

class TypeInfo_Ao : TypeInfo_Af
{
alias F = ifloat;

override string toString() const { return (F[]).stringof; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(F);
}
mixin TypeInfo_A_T!ifloat;
}
103 changes: 8 additions & 95 deletions src/rt/typeinfo/ti_Ag.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,140 +15,53 @@ module rt.typeinfo.ti_Ag;

private import core.stdc.string;
private import core.internal.string;
private import rt.util.typeinfo;

// byte[]

class TypeInfo_Ag : TypeInfo_Array
{
override bool opEquals(Object o) { return TypeInfo.opEquals(o); }

override string toString() const { return "byte[]"; }

override size_t getHash(scope const void* p) @trusted const
{
const s = *cast(const void[]*)p;
return hashOf(s);
}

override bool equals(in void* p1, in void* p2) const
{
byte[] s1 = *cast(byte[]*)p1;
byte[] s2 = *cast(byte[]*)p2;

return s1.length == s2.length &&
memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0;
}

override int compare(in void* p1, in void* p2) const
{
byte[] s1 = *cast(byte[]*)p1;
byte[] s2 = *cast(byte[]*)p2;
size_t len = s1.length;

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int result = s1[u] - s2[u];
if (result)
return result;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(byte);
}
mixin TypeInfo_A_T!byte;
}


// ubyte[]

class TypeInfo_Ah : TypeInfo_Ag
{
override string toString() const { return "ubyte[]"; }

override int compare(in void* p1, in void* p2) const
{
char[] s1 = *cast(char[]*)p1;
char[] s2 = *cast(char[]*)p2;

return dstrcmp(s1, s2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(ubyte);
}
mixin TypeInfo_A_T!ubyte;
}

// void[]

class TypeInfo_Av : TypeInfo_Ah
{
override string toString() const { return "void[]"; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(void);
}
mixin TypeInfo_A_T!void;
}

// bool[]

class TypeInfo_Ab : TypeInfo_Ah
{
override string toString() const { return "bool[]"; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(bool);
}
mixin TypeInfo_A_T!bool;
}

// char[]

class TypeInfo_Aa : TypeInfo_Ah
{
override string toString() const { return "char[]"; }

override size_t getHash(scope const void* p) @trusted const
{
char[] s = *cast(char[]*)p;
return hashOf(s);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(char);
}
mixin TypeInfo_A_T!char;
}

// string

class TypeInfo_Aya : TypeInfo_Aa
{
override string toString() const { return "immutable(char)[]"; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(immutable(char));
}
mixin TypeInfo_A_T!(immutable(char));
}

// const(char)[]

class TypeInfo_Axa : TypeInfo_Aa
{
override string toString() const { return "const(char)[]"; }

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(const(char));
}
mixin TypeInfo_A_T!(const(char));
}
Loading