mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Updated lifetime.d with a 32bit faster codepath for overflow checks.
This commit is contained in:
@@ -85,9 +85,20 @@ private
|
||||
|
||||
size_t length_adjust(size_t sizeelem, size_t newlength)
|
||||
{
|
||||
size_t newsize = sizeelem * newlength;
|
||||
if (newsize / newlength != sizeelem)
|
||||
onOutOfMemoryError();
|
||||
size_t newsize = void;
|
||||
static if (size_t.sizeof < ulong.sizeof)
|
||||
{
|
||||
ulong s = cast(ulong)sizeelem * cast(ulong)newlength;
|
||||
if (s > size_t.max)
|
||||
onOutOfMemoryError();
|
||||
newsize = cast(size_t)s;
|
||||
}
|
||||
else
|
||||
{
|
||||
newsize = sizeelem * newlength;
|
||||
if (newsize / newlength != sizeelem)
|
||||
onOutOfMemoryError();
|
||||
}
|
||||
return newsize;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user