mirror of
https://github.com/OlafvdSpek/ctemplate.git
synced 2025-09-28 19:05:49 +08:00
Drop const from size_t
This commit is contained in:
parent
8f667d33ae
commit
1baad884af
|
@ -207,13 +207,13 @@ class Gladiator {
|
||||||
// the arena concept. If it does pose a problem, flesh out the
|
// the arena concept. If it does pose a problem, flesh out the
|
||||||
// ArrayGladiator class below.
|
// ArrayGladiator class below.
|
||||||
|
|
||||||
void* operator new(const size_t size) {
|
void* operator new(size_t size) {
|
||||||
void* ret = ::operator new(1 + size);
|
void* ret = ::operator new(1 + size);
|
||||||
static_cast<char *>(ret)[size] = 1; // mark as heap-allocated
|
static_cast<char *>(ret)[size] = 1; // mark as heap-allocated
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// the ignored parameter keeps us from stepping on placement new
|
// the ignored parameter keeps us from stepping on placement new
|
||||||
template<class T> void* operator new(const size_t size, const int ignored,
|
template<class T> void* operator new(size_t size, const int ignored,
|
||||||
T* allocator) {
|
T* allocator) {
|
||||||
if (allocator) {
|
if (allocator) {
|
||||||
void* ret = allocator->AllocAligned(1 + size,
|
void* ret = allocator->AllocAligned(1 + size,
|
||||||
|
@ -224,7 +224,7 @@ class Gladiator {
|
||||||
return operator new(size); // this is the function above
|
return operator new(size); // this is the function above
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void operator delete(void* memory, const size_t size) {
|
void operator delete(void* memory, size_t size) {
|
||||||
if (static_cast<char*>(memory)[size]) {
|
if (static_cast<char*>(memory)[size]) {
|
||||||
assert (1 == static_cast<char *>(memory)[size]);
|
assert (1 == static_cast<char *>(memory)[size]);
|
||||||
::operator delete(memory);
|
::operator delete(memory);
|
||||||
|
@ -234,7 +234,7 @@ class Gladiator {
|
||||||
// the Boolean marker flag.
|
// the Boolean marker flag.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<class T> void operator delete(void* memory, const size_t size,
|
template<class T> void operator delete(void* memory, size_t size,
|
||||||
const int ign, T* allocator) {
|
const int ign, T* allocator) {
|
||||||
// This "placement delete" can only be called if the constructor
|
// This "placement delete" can only be called if the constructor
|
||||||
// throws an exception.
|
// throws an exception.
|
||||||
|
@ -258,28 +258,28 @@ class ArenaOnlyGladiator {
|
||||||
// virtual ~ArenaOnlyGladiator() { }
|
// virtual ~ArenaOnlyGladiator() { }
|
||||||
|
|
||||||
// can't just return NULL here -- compiler gives a warning. :-|
|
// can't just return NULL here -- compiler gives a warning. :-|
|
||||||
void* operator new(const size_t /*size*/) {
|
void* operator new(size_t /*size*/) {
|
||||||
assert(0);
|
assert(0);
|
||||||
return reinterpret_cast<void *>(1);
|
return reinterpret_cast<void *>(1);
|
||||||
}
|
}
|
||||||
void* operator new[](const size_t /*size*/) {
|
void* operator new[](size_t /*size*/) {
|
||||||
assert(0);
|
assert(0);
|
||||||
return reinterpret_cast<void *>(1);
|
return reinterpret_cast<void *>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the ignored parameter keeps us from stepping on placement new
|
// the ignored parameter keeps us from stepping on placement new
|
||||||
template<class T> void* operator new(const size_t size, const int ignored,
|
template<class T> void* operator new(size_t size, const int ignored,
|
||||||
T* allocator) {
|
T* allocator) {
|
||||||
assert(allocator);
|
assert(allocator);
|
||||||
return allocator->AllocAligned(size, BaseArena::kDefaultAlignment);
|
return allocator->AllocAligned(size, BaseArena::kDefaultAlignment);
|
||||||
}
|
}
|
||||||
template<class T> void* operator new[](const size_t size,
|
template<class T> void* operator new[](size_t size,
|
||||||
const int ignored, T* allocator) {
|
const int ignored, T* allocator) {
|
||||||
assert(allocator);
|
assert(allocator);
|
||||||
return allocator->AllocAligned (size, BaseArena::kDefaultAlignment);
|
return allocator->AllocAligned (size, BaseArena::kDefaultAlignment);
|
||||||
}
|
}
|
||||||
void operator delete(void* /*memory*/, const size_t /*size*/) { }
|
void operator delete(void* /*memory*/, size_t /*size*/) { }
|
||||||
template<class T> void operator delete(void* memory, const size_t size,
|
template<class T> void operator delete(void* memory, size_t size,
|
||||||
const int ign, T* allocator) { }
|
const int ign, T* allocator) { }
|
||||||
void operator delete [](void* /*memory*/) { }
|
void operator delete [](void* /*memory*/) { }
|
||||||
template<class T> void operator delete(void* memory,
|
template<class T> void operator delete(void* memory,
|
||||||
|
@ -295,7 +295,7 @@ class ArenaOnlyGladiator {
|
||||||
|
|
||||||
class ArrayGladiator : public Gladiator {
|
class ArrayGladiator : public Gladiator {
|
||||||
public:
|
public:
|
||||||
void * operator new[] (const size_t size) {
|
void * operator new[] (size_t size) {
|
||||||
const int sizeplus = size + kHeaderSize;
|
const int sizeplus = size + kHeaderSize;
|
||||||
void * const ret = ::operator new(sizeplus);
|
void * const ret = ::operator new(sizeplus);
|
||||||
*static_cast<Arena **>(ret) = NULL; // mark as heap-allocated
|
*static_cast<Arena **>(ret) = NULL; // mark as heap-allocated
|
||||||
|
@ -303,7 +303,7 @@ class ArrayGladiator : public Gladiator {
|
||||||
return ret + kHeaderSize;
|
return ret + kHeaderSize;
|
||||||
}
|
}
|
||||||
// the ignored parameter keeps us from stepping on placement new
|
// the ignored parameter keeps us from stepping on placement new
|
||||||
template<class T> void * operator new[] (const size_t size,
|
template<class T> void * operator new[] (size_t size,
|
||||||
const int ignored, T * allocator) {
|
const int ignored, T * allocator) {
|
||||||
if (allocator) {
|
if (allocator) {
|
||||||
const int sizeplus = size + kHeaderSize;
|
const int sizeplus = size + kHeaderSize;
|
||||||
|
@ -319,7 +319,7 @@ class ArrayGladiator : public Gladiator {
|
||||||
void operator delete [] (void * memory) {
|
void operator delete [] (void * memory) {
|
||||||
memory -= kHeaderSize;
|
memory -= kHeaderSize;
|
||||||
Arena * const arena = *static_cast<Arena **>(memory);
|
Arena * const arena = *static_cast<Arena **>(memory);
|
||||||
const size_t sizeplus = *static_cast<size_t *>(memory + sizeof(arena));
|
size_t sizeplus = *static_cast<size_t *>(memory + sizeof(arena));
|
||||||
if (arena) {
|
if (arena) {
|
||||||
arena->SlowFree(memory, sizeplus);
|
arena->SlowFree(memory, sizeplus);
|
||||||
} else {
|
} else {
|
||||||
|
@ -331,7 +331,7 @@ class ArrayGladiator : public Gladiator {
|
||||||
// This "placement delete" can only be called if the constructor
|
// This "placement delete" can only be called if the constructor
|
||||||
// throws an exception.
|
// throws an exception.
|
||||||
memory -= kHeaderSize;
|
memory -= kHeaderSize;
|
||||||
const size_t sizeplus = *static_cast<size_t *>(memory + sizeof(Arena *));
|
size_t sizeplus = *static_cast<size_t *>(memory + sizeof(Arena *));
|
||||||
if (allocator) {
|
if (allocator) {
|
||||||
allocator->Free(memory, 1 + size);
|
allocator->Free(memory, 1 + size);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user