XPath: memory_block is now POD (no more offsetof warnings)

git-svn-id: http://pugixml.googlecode.com/svn/trunk@666 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine 2010-08-29 15:28:59 +00:00
parent 80cbba6ec5
commit f2509e0395

View File

@ -43,8 +43,9 @@ typedef __int32 int32_t;
#if defined(_MSC_VER) #if defined(_MSC_VER)
# pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4127) // conditional expression is constant
# pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
# pragma warning(disable: 4324) // structure was padded due to __declspec(align()) # pragma warning(disable: 4324) // structure was padded due to __declspec(align())
# pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
# pragma warning(disable: 4702) // unreachable code
# pragma warning(disable: 4996) // this function or variable may be unsafe # pragma warning(disable: 4996) // this function or variable may be unsafe
#endif #endif
@ -965,17 +966,14 @@ namespace pugi
{ {
struct memory_block struct memory_block
{ {
memory_block(): next(0), size(0)
{
}
memory_block* next; memory_block* next;
size_t size;
char data[xpath_memory_block_size]; char data[xpath_memory_block_size];
}; };
memory_block* _root; memory_block* _root;
size_t _root_size;
memory_block _first; memory_block _first;
public: public:
@ -1007,8 +1005,11 @@ namespace pugi
get_memory_deallocation_function()(alloc); get_memory_deallocation_function()(alloc);
} }
xpath_allocator(): _root(&_first) xpath_allocator()
{ {
_root = &_first;
_root_size = 0;
_first.next = 0;
} }
void* allocate(size_t size) void* allocate(size_t size)
@ -1016,10 +1017,10 @@ namespace pugi
// align size so that we're able to store pointers in subsequent blocks // align size so that we're able to store pointers in subsequent blocks
size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1); size = (size + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
if (_root->size + size <= xpath_memory_block_size) if (_root_size + size <= xpath_memory_block_size)
{ {
void* buf = _root->data + _root->size; void* buf = _root->data + _root_size;
_root->size += size; _root_size += size;
return buf; return buf;
} }
else else
@ -1031,9 +1032,9 @@ namespace pugi
if (!block) return 0; if (!block) return 0;
block->next = _root; block->next = _root;
block->size = size;
_root = block; _root = block;
_root_size = size;
return block->data; return block->data;
} }