[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: texi2any --html performance improvement - XS over
From: |
Gavin D. Smith |
Subject: |
branch master updated: texi2any --html performance improvement - XS override |
Date: |
Fri, 03 Jun 2022 20:32:32 -0400 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 3a1049f252 texi2any --html performance improvement - XS override
3a1049f252 is described below
commit 3a1049f252eb2778cd91560a287bfa6ff6219c91
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Jun 4 01:32:21 2022 +0100
texi2any --html performance improvement - XS override
* tp/Texinfo/XS/MiscXS.xs,
* tp/Texinfo/XS/misc.c (xs_xml_protect_text): New function.
* tp/Texinfo/Convert/Converter.pm: Override xml_protect_text
with XS implementation.
---
ChangeLog | 9 +++++++
tp/Texinfo/Convert/Converter.pm | 15 +++++++++++-
tp/Texinfo/XS/MiscXS.xs | 27 +++++++++++++++++++--
tp/Texinfo/XS/misc.c | 52 ++++++++++++++++++++++++++++++++++++++++-
tp/Texinfo/XS/miscxs.h | 1 +
5 files changed, 100 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1e14b62b80..0397720527 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-06-05 Gavin Smith <gavinsmith0123@gmail.com>
+
+ texi2any --html performance improvement - XS override
+
+ * tp/Texinfo/XS/MiscXS.xs,
+ * tp/Texinfo/XS/misc.c (xs_xml_protect_text): New function.
+ * tp/Texinfo/Convert/Converter.pm: Override xml_protect_text
+ with XS implementation.
+
2022-06-05 Gavin Smith <gavinsmith0123@gmail.com>
texi2any --html performance improvement
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 46664be890..c4e8528e63 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -57,6 +57,18 @@ xml_accents
$VERSION = '6.8dev';
+our $module_loaded = 0;
+sub import {
+ if (!$module_loaded) {
+ Texinfo::XSLoader::override(
+ "Texinfo::Convert::Converter::xml_protect_text",
+ "Texinfo::MiscXS::xml_protect_text");
+ $module_loaded = 1;
+ }
+ # The usual import method
+ goto &Exporter::import;
+}
+
my %defaults = (
'documentlanguage' => undef,
@@ -1383,7 +1395,8 @@ sub xml_format_text_with_numeric_entities($$)
return $text;
}
-sub xml_protect_text($$)
+# Note: has an XS override
+sub xml_protect_text
{
my $self = shift;
my $text = shift;
diff --git a/tp/Texinfo/XS/MiscXS.xs b/tp/Texinfo/XS/MiscXS.xs
index 04e9454c5c..cd1307ff48 100644
--- a/tp/Texinfo/XS/MiscXS.xs
+++ b/tp/Texinfo/XS/MiscXS.xs
@@ -13,7 +13,7 @@
MODULE = Texinfo::MiscXS PACKAGE = Texinfo::MiscXS PREFIX = xs_
-# Copyright 2016 Free Software Foundation, Inc.
+# Copyright 2016-2022 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -86,7 +86,7 @@ xs_unicode_text (text_in, ...)
if (SvOK(ST(1)))
in_code = (int) SvIV(ST(1));
}
- /* Make sure the input is in UTF8. */
+ /* Make sure the input is in UTF-8. */
if (!SvUTF8 (text_in))
sv_utf8_upgrade (text_in);
@@ -132,3 +132,26 @@ xs_parse_texi_regex (text)
PUSHs(sv_newmortal());
sv_setpv((SV*)ST(5), new_text);
SvUTF8_on(ST(5));
+
+SV *
+xs_xml_protect_text (self, text_in)
+ SV *self
+ SV *text_in
+ PREINIT:
+ char *text;
+ char *retval;
+ CODE:
+ /* Make sure the input is in UTF-8. */
+ if (!SvUTF8 (text_in))
+ sv_utf8_upgrade (text_in);
+
+ text = SvPV_nolen (text_in);
+
+ retval = xs_xml_protect_text (text);
+
+ RETVAL = newSVpv (retval, 0);
+ SvUTF8_on (RETVAL);
+
+ OUTPUT:
+ RETVAL
+
diff --git a/tp/Texinfo/XS/misc.c b/tp/Texinfo/XS/misc.c
index 91b4708fdd..c3b3427043 100644
--- a/tp/Texinfo/XS/misc.c
+++ b/tp/Texinfo/XS/misc.c
@@ -1,4 +1,4 @@
-/* Copyright 2010-2019 Free Software Foundation, Inc.
+/* Copyright 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -634,3 +634,53 @@ void xs_parse_texi_regex (SV *text_in,
return;
}
+
+char *
+xs_xml_protect_text (char *text)
+{
+ char *p, *q;
+ static char *new;
+ int new_space, new_len;
+
+ dTHX; /* Perl boilerplate. */
+
+ p = text;
+ new_space = strlen (text);
+ new = realloc (new, new_space + 1);
+ new_len = 0;
+
+#define ADDN(s, n) \
+ if (new_len + n - 1 >= new_space - 1) \
+ { \
+ new_space += n; \
+ new = realloc (new, (new_space *= 2) + 1); \
+ } \
+ memcpy(new + new_len, s, n); \
+ new_len += n;
+
+ while (1)
+ {
+ q = p + strcspn (p, "<>&\"");
+ ADDN(p, q - p);
+ if (!*q)
+ break;
+ switch (*q)
+ {
+ case '<':
+ ADDN("<", 4);
+ break;
+ case '>':
+ ADDN(">", 4);
+ break;
+ case '&':
+ ADDN("&", 5);
+ break;
+ case '"':
+ ADDN(""", 6);
+ break;
+ }
+ p = q + 1;
+ }
+ new[new_len] = '\0';
+ return new;
+}
diff --git a/tp/Texinfo/XS/miscxs.h b/tp/Texinfo/XS/miscxs.h
index 745e6ec8e9..4eca89ccf3 100644
--- a/tp/Texinfo/XS/miscxs.h
+++ b/tp/Texinfo/XS/miscxs.h
@@ -9,3 +9,4 @@ void xs_parse_texi_regex (SV *text,
char **,
char **,
char **);
+char *xs_xml_protect_text (char *);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: texi2any --html performance improvement - XS override,
Gavin D. Smith <=