fixes #431 :: apply DMDFE 1.062; thanks SiegeLord

This commit is contained in:
Moritz Warning
2010-09-27 00:06:28 +02:00
parent b032e3d1f7
commit c4e255206a
35 changed files with 918 additions and 335 deletions

View File

@@ -1,8 +1,8 @@
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2010 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// www.digitalmars.com
// http://www.digitalmars.com
// License for redistribution is by either the Artistic License
// in artistic.txt, or the GNU General Public License in gnu.txt.
// See the included readme.txt for details.
@@ -48,14 +48,15 @@
Array::Array()
{
data = NULL;
data = SMALLARRAYCAP ? &smallarray[0] : NULL;
dim = 0;
allocdim = 0;
allocdim = SMALLARRAYCAP;
}
Array::~Array()
{
mem.free(data);
if (data != &smallarray[0])
mem.free(data);
}
void Array::mark()
@@ -68,11 +69,30 @@ void Array::mark()
void Array::reserve(unsigned nentries)
{
//printf("Array::reserve: size = %d, offset = %d, nbytes = %d\n", size, offset, nbytes);
//printf("Array::reserve: dim = %d, allocdim = %d, nentries = %d\n", dim, allocdim, nentries);
if (allocdim - dim < nentries)
{
allocdim = dim + nentries;
data = (void **)mem.realloc(data, allocdim * sizeof(*data));
if (allocdim == 0)
{ // Not properly initialized, someone memset it to zero
if (nentries <= SMALLARRAYCAP)
{ allocdim = SMALLARRAYCAP;
data = SMALLARRAYCAP ? &smallarray[0] : NULL;
}
else
{ allocdim = nentries;
data = (void **)mem.malloc(allocdim * sizeof(*data));
}
}
else if (allocdim == SMALLARRAYCAP)
{
allocdim = dim + nentries;
data = (void **)mem.malloc(allocdim * sizeof(*data));
memcpy(data, &smallarray[0], dim * sizeof(*data));
}
else
{ allocdim = dim + nentries;
data = (void **)mem.realloc(data, allocdim * sizeof(*data));
}
}
}
@@ -88,7 +108,17 @@ void Array::setDim(unsigned newdim)
void Array::fixDim()
{
if (dim != allocdim)
{ data = (void **)mem.realloc(data, dim * sizeof(*data));
{
if (allocdim >= SMALLARRAYCAP)
{
if (dim <= SMALLARRAYCAP)
{
memcpy(&smallarray[0], data, dim * sizeof(*data));
mem.free(data);
}
else
data = (void **)mem.realloc(data, dim * sizeof(*data));
}
allocdim = dim;
}
}

View File

@@ -427,7 +427,9 @@ int Port::isInfinity(double r)
#undef signbit
int Port::Signbit(double r)
{
return (long)(((long *)&r)[1] & 0x80000000);
union { double d; long long ll; } u;
u.d = r;
return u.ll < 0;
}
double Port::floor(double d)

View File

@@ -318,11 +318,17 @@ struct OutBuffer : Object
struct Array : Object
{
unsigned dim;
unsigned allocdim;
void **data;
private:
unsigned allocdim;
#define SMALLARRAYCAP 1
void *smallarray[SMALLARRAYCAP]; // inline storage for small arrays
public:
Array();
~Array();
//Array(const Array&);
void mark();
char *toChars();