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

Commit

Permalink
[Refactoring] Gather common code in rt.util.typeinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Oct 24, 2014
1 parent 64a0bca commit 9e7ec9c
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 512 deletions.
1 change: 1 addition & 0 deletions mak/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ MANIFEST=\
src\rt\util\hash.d \
src\rt\util\random.d \
src\rt\util\string.d \
src\rt\util\typeinfo.d \
src\rt\util\utf.d \
src\rt\util\container\array.d \
src\rt\util\container\common.d \
Expand Down
1 change: 1 addition & 0 deletions mak/SRCS
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ SRCS=\
src\rt\util\hash.d \
src\rt\util\random.d \
src\rt\util\string.d \
src\rt\util\typeinfo.d \
src\rt\util\utf.d \
src\rt\util\container\array.d \
src\rt\util\container\common.d \
Expand Down
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acdouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acdouble;

private import rt.typeinfo.ti_cdouble;
private import rt.util.hash;
private import rt.util.typeinfo;

// cdouble[]

class TypeInfo_Ar : TypeInfo_Array
{
alias F = cdouble;

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

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

override size_t getHash(in void* p) @trusted const
{
cdouble[] s = *cast(cdouble[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * cdouble.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
cdouble[] s1 = *cast(cdouble[]*)p1;
cdouble[] s2 = *cast(cdouble[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return false;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_r._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

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

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_r._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(cdouble);
return cast(inout)typeid(F);
}
}
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acfloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acfloat;

private import rt.typeinfo.ti_cfloat;
private import rt.util.hash;
private import rt.util.typeinfo;

// cfloat[]

class TypeInfo_Aq : TypeInfo_Array
{
alias F = cfloat;

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

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

override size_t getHash(in void* p) @trusted const
{
cfloat[] s = *cast(cfloat[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * cfloat.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
cfloat[] s1 = *cast(cfloat[]*)p1;
cfloat[] s2 = *cast(cfloat[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return false;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_q._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

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

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_q._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(cfloat);
return cast(inout)typeid(F);
}
}
43 changes: 8 additions & 35 deletions src/rt/typeinfo/ti_Acreal.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,62 +13,35 @@
*/
module rt.typeinfo.ti_Acreal;

private import rt.typeinfo.ti_creal;
private import rt.util.hash;
private import rt.util.typeinfo;

// creal[]

class TypeInfo_Ac : TypeInfo_Array
{
alias F = creal;

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

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

override size_t getHash(in void* p) @trusted const
{
creal[] s = *cast(creal[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * creal.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
creal[] s1 = *cast(creal[]*)p1;
creal[] s2 = *cast(creal[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_c._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

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

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_c._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(creal);
return cast(inout)typeid(F);
}
}
49 changes: 12 additions & 37 deletions src/rt/typeinfo/ti_Adouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,49 @@
*/
module rt.typeinfo.ti_Adouble;

private import rt.typeinfo.ti_double;
private import rt.util.hash;
private import rt.util.typeinfo;

// double[]

class TypeInfo_Ad : TypeInfo_Array
{
alias F = double;

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

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

override size_t getHash(in void* p) @trusted const
{
double[] s = *cast(double[]*)p;
return rt.util.hash.hashOf(s.ptr, s.length * double.sizeof);
return Array!F.hashOf(*cast(F[]*)p);
}

override bool equals(in void* p1, in void* p2) const
{
double[] s1 = *cast(double[]*)p1;
double[] s2 = *cast(double[]*)p2;
size_t len = s1.length;

if (len != s2.length)
return 0;
for (size_t u = 0; u < len; u++)
{
if (!TypeInfo_d._equals(s1[u], s2[u]))
return false;
}
return true;
return Array!F.equals(*cast(F[]*)p1, *cast(F[]*)p2);
}

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

if (s2.length < len)
len = s2.length;
for (size_t u = 0; u < len; u++)
{
int c = TypeInfo_d._compare(s1[u], s2[u]);
if (c)
return c;
}
if (s1.length < s2.length)
return -1;
else if (s1.length > s2.length)
return 1;
return 0;
return Array!F.compare(*cast(F[]*)p1, *cast(F[]*)p2);
}

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

// idouble[]

class TypeInfo_Ap : TypeInfo_Ad
{
override string toString() const { return "idouble[]"; }
alias F = idouble;

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

override @property inout(TypeInfo) next() inout
{
return cast(inout)typeid(idouble);
return cast(inout)typeid(F);
}
}
Loading

0 comments on commit 9e7ec9c

Please sign in to comment.