xmllite: Shrink buffer when enough data processed.

This commit is contained in:
Nikolay Sivov 2012-12-21 09:35:30 +04:00 committed by Alexandre Julliard
parent d8a0da9d8f
commit beffac006c
1 changed files with 18 additions and 0 deletions

View File

@ -481,6 +481,7 @@ static void readerinput_switchencoding(xmlreaderinput *readerinput, xml_encoding
{ {
readerinput_grow(readerinput, len); readerinput_grow(readerinput, len);
memcpy(dest->data, src->cur, len); memcpy(dest->data, src->cur, len);
dest->written += len*sizeof(WCHAR);
readerinput->buffer->code_page = cp; readerinput->buffer->code_page = cp;
return; return;
} }
@ -491,6 +492,22 @@ static void readerinput_switchencoding(xmlreaderinput *readerinput, xml_encoding
MultiByteToWideChar(cp, 0, src->cur, len, ptr, dest_len); MultiByteToWideChar(cp, 0, src->cur, len, ptr, dest_len);
ptr[dest_len] = 0; ptr[dest_len] = 0;
readerinput->buffer->code_page = cp; readerinput->buffer->code_page = cp;
dest->written += dest_len*sizeof(WCHAR);
}
/* shrinks parsed data a buffer begins with */
static void reader_shrink(xmlreader *reader)
{
encoded_buffer *buffer = &reader->input->buffer->utf16;
/* avoid to move too often using threshold shrink length */
if (buffer->cur - buffer->data > buffer->written / 2)
{
buffer->written -= buffer->cur - buffer->data;
memmove(buffer->data, buffer->cur, buffer->written);
buffer->cur = buffer->data;
*(WCHAR*)&buffer->cur[buffer->written] = 0;
}
} }
static inline const WCHAR *reader_get_cur(xmlreader *reader) static inline const WCHAR *reader_get_cur(xmlreader *reader)
@ -772,6 +789,7 @@ static HRESULT reader_parse_comment(xmlreader *reader)
/* skip '<!--' */ /* skip '<!--' */
reader_skipn(reader, 4); reader_skipn(reader, 4);
reader_shrink(reader);
ptr = start = reader_get_cur(reader); ptr = start = reader_get_cur(reader);
while (*ptr) while (*ptr)