From 8d8bf2c5f622671ac3c2e8f136bb060c517c3a19 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 17 Sep 2003 19:36:25 +0000 Subject: [PATCH] small fix from Rob Richards for input filename fixes for --repeat and * parserInternals.c: small fix from Rob Richards for input filename * xmllint.c: fixes for --repeat and --memory/--stream for speed tests * xmlIO: adding a guard in one function Daniel --- ChangeLog | 6 ++++++ parserInternals.c | 2 +- xmlIO.c | 2 ++ xmllint.c | 42 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79368aac..98d21127 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Sep 17 21:33:57 CEST 2003 Daniel Veillard + + * parserInternals.c: small fix from Rob Richards for input filename + * xmllint.c: fixes for --repeat and --memory/--stream for speed tests + * xmlIO: adding a guard in one function + Wed Sep 17 15:57:44 CEST 2003 Daniel Veillard * SAX2.c xmlreader.c include/libxml/parser.h: more performance hunting diff --git a/parserInternals.c b/parserInternals.c index 2dfeca90..5332eed5 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -2167,7 +2167,7 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { return(NULL); } - inputStream->filename = (const char *) URI; + inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI); inputStream->directory = directory; inputStream->buf = buf; diff --git a/xmlIO.c b/xmlIO.c index 0c409464..c318945d 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -1643,6 +1643,8 @@ xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { */ void xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { + if (in == NULL) return; + if (in->raw) { xmlBufferFree(in->raw); in->raw = NULL; diff --git a/xmllint.c b/xmllint.c index 21e3201a..100a83d4 100644 --- a/xmllint.c +++ b/xmllint.c @@ -609,8 +609,28 @@ static void processNode(xmlTextReaderPtr reader) { static void streamFile(char *filename) { xmlTextReaderPtr reader; int ret; +#ifdef HAVE_SYS_MMAN_H + int fd = -1; + struct stat info; + const char *base = NULL; + xmlParserInputBufferPtr input = NULL; + + if (memory) { + if (stat(filename, &info) < 0) + return; + if ((fd = open(filename, O_RDONLY)) < 0) + return; + base = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0) ; + if (base == (void *) MAP_FAILED) + return; + + input = xmlParserInputBufferCreateMem((char *) base, info.st_size, + XML_CHAR_ENCODING_NONE); + reader = xmlNewTextReader(input, filename); + } else +#endif + reader = xmlNewTextReaderFilename(filename); - reader = xmlNewTextReaderFilename(filename); if (reader != NULL) { if (valid) xmlTextReaderSetParserProp(reader, XML_PARSER_VALIDATE, 1); @@ -685,6 +705,13 @@ static void streamFile(char *filename) { fprintf(stderr, "Unable to open %s\n", filename); progresult = 1; } +#ifdef HAVE_SYS_MMAN_H + if (memory) { + xmlFreeParserInputBuffer(input); + munmap((char *) base, info.st_size); + close(fd); + } +#endif } /************************************************************************ @@ -1426,9 +1453,12 @@ main(int argc, char **argv) { (!strcmp(argv[i], "--auto"))) generate++; else if ((!strcmp(argv[i], "-repeat")) || - (!strcmp(argv[i], "--repeat"))) - repeat++; - else if ((!strcmp(argv[i], "-push")) || + (!strcmp(argv[i], "--repeat"))) { + if (repeat) + repeat *= 10; + else + repeat = 100; + } else if ((!strcmp(argv[i], "-push")) || (!strcmp(argv[i], "--push"))) push++; #ifdef HAVE_SYS_MMAN_H @@ -1664,7 +1694,7 @@ main(int argc, char **argv) { /* Remember file names. "-" means stdin. */ if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { if (repeat) { - for (acount = 0;acount < 100 * repeat;acount++) + for (acount = 0;acount < repeat;acount++) if (stream != 0) streamFile(argv[i]); else @@ -1677,7 +1707,7 @@ main(int argc, char **argv) { } files ++; if ((timing) && (repeat)) { - endTimer("100 iterations"); + endTimer("%d iterations", repeat); } } }