1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-27 18:50:07 +03:00

io: Fine-tune initial IO buffer size

This commit is contained in:
Nick Wellnhofer 2024-07-07 18:52:17 +02:00
parent 7148b77820
commit a6f54f055b
3 changed files with 14 additions and 4 deletions

@ -5,6 +5,16 @@
#include <libxml/tree.h>
#include <libxml/xmlversion.h>
/*
* Initial buffer size should include
*
* - MINLEN = 4000 (I/O chunk size)
* - INPUT_CHUNK = 250 (parser prefetch)
* - LINE_LEN = 80 (shrink limit for error messages)
* - some amount for unshrunken content.
*/
#define XML_IO_BUFFER_SIZE 6000
XML_HIDDEN void
xmlInitIOCallbacks(void);

@ -1310,7 +1310,7 @@ xmlInputSetEncodingHandler(xmlParserInputPtr input,
return(XML_ERR_OK);
}
buf = xmlBufCreate(INPUT_CHUNK + 4000 /* MINLEN */ + LINE_LEN);
buf = xmlBufCreate(XML_IO_BUFFER_SIZE);
if (buf == NULL) {
xmlCharEncCloseFunc(handler);
return(XML_ERR_NO_MEMORY);

@ -1205,7 +1205,7 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) {
return(NULL);
}
memset(ret, 0, sizeof(xmlParserInputBuffer));
ret->buffer = xmlBufCreate(INPUT_CHUNK + MINLEN + 80 /* LINE_LEN */);
ret->buffer = xmlBufCreate(XML_IO_BUFFER_SIZE);
if (ret->buffer == NULL) {
xmlFree(ret);
return(NULL);
@ -1218,7 +1218,7 @@ xmlAllocParserInputBuffer(xmlCharEncoding enc) {
}
}
if (ret->encoder != NULL)
ret->raw = xmlBufCreate(MINLEN);
ret->raw = xmlBufCreate(XML_IO_BUFFER_SIZE);
else
ret->raw = NULL;
ret->readcallback = NULL;
@ -2161,7 +2161,7 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
buf = in->buffer;
} else {
if (in->raw == NULL) {
in->raw = xmlBufCreate(MINLEN);
in->raw = xmlBufCreate(XML_IO_BUFFER_SIZE);
}
buf = in->raw;
}