[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/xspara.c (xspara_add_text, xspara
From: |
Gavin D. Smith |
Subject: |
branch master updated: * tp/Texinfo/XS/xspara.c (xspara_add_text, xspara_add_next): Receive length of strings as an argument and return lengths in structure. This avoids having to call strlen. |
Date: |
Sat, 08 Apr 2023 17:33:37 -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 ab35a34b1c * tp/Texinfo/XS/xspara.c (xspara_add_text,
xspara_add_next): Receive length of strings as an argument and return lengths
in structure. This avoids having to call strlen.
ab35a34b1c is described below
commit ab35a34b1ccec63cc6327f840dbf6073e6d236bd
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Apr 8 22:33:29 2023 +0100
* tp/Texinfo/XS/xspara.c (xspara_add_text, xspara_add_next):
Receive length of strings as an argument and return lengths in
structure. This avoids having to call strlen.
---
ChangeLog | 6 ++++++
tp/Texinfo/XS/XSParagraph.xs | 19 ++++++++++---------
tp/Texinfo/XS/text.h | 7 ++++++-
tp/Texinfo/XS/xspara.c | 18 +++++-------------
tp/Texinfo/XS/xspara.h | 6 ++++--
5 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ad8524be77..c3e5db844a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-04-08 Gavin Smith <gavinsmith0123@gmail.com>
+
+ * tp/Texinfo/XS/xspara.c (xspara_add_text, xspara_add_next):
+ Receive length of strings as an argument and return lengths in
+ structure. This avoids having to call strlen.
+
2023-04-08 Gavin Smith <gavinsmith0123@gmail.com>
* tp/Texinfo/Convert/Plaintext.pm (_convert): Inline the most
diff --git a/tp/Texinfo/XS/XSParagraph.xs b/tp/Texinfo/XS/XSParagraph.xs
index 27e10e0309..06f2edb8fd 100644
--- a/tp/Texinfo/XS/XSParagraph.xs
+++ b/tp/Texinfo/XS/XSParagraph.xs
@@ -18,7 +18,7 @@
MODULE = Texinfo::Convert::Paragraph PACKAGE = Texinfo::Convert::Paragraph
PREFIX = xspara_
-# Copyright 2010-2020 Free Software Foundation, Inc.
+# Copyright 2010-2023 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
@@ -145,22 +145,23 @@ xspara_end (paragraph)
SV *
xspara_add_text (paragraph, text_in)
SV *paragraph
- SV * text_in
+ SV *text_in
PREINIT:
char *text;
- char *retval;
+ STRLEN text_len;
+ TEXT retval;
CODE:
/* Always convert the input to UTF8 with sv_utf8_upgrade, so we can
process it properly in xspara_add_next. */
if (!SvUTF8 (text_in))
sv_utf8_upgrade (text_in);
- text = SvPV_nolen (text_in);
+ text = SvPV (text_in, text_len);
xspara_set_state (paragraph);
- retval = xspara_add_text (text);
+ retval = xspara_add_text (text, text_len);
- RETVAL = newSVpv (retval, 0);
+ RETVAL = newSVpv (retval.text ? retval.text : "", retval.end);
SvUTF8_on (RETVAL);
OUTPUT:
@@ -169,11 +170,11 @@ xspara_add_text (paragraph, text_in)
SV *
xspara_add_next (paragraph, text_in, ...)
SV *paragraph
- SV * text_in
+ SV *text_in
PREINIT:
char *text;
STRLEN text_len;
- char *retval;
+ TEXT retval;
SV *arg_in;
int transparent = 0;
CODE:
@@ -195,7 +196,7 @@ xspara_add_next (paragraph, text_in, ...)
xspara_set_state (paragraph);
retval = xspara_add_next (text, text_len, transparent);
- RETVAL = newSVpv (retval, 0);
+ RETVAL = newSVpv (retval.text ? retval.text : "", retval.end);
SvUTF8_on (RETVAL);
OUTPUT:
diff --git a/tp/Texinfo/XS/text.h b/tp/Texinfo/XS/text.h
index 7f14b3d297..7d358e5955 100644
--- a/tp/Texinfo/XS/text.h
+++ b/tp/Texinfo/XS/text.h
@@ -1,4 +1,4 @@
-/* Copyright 2014, 2015, 2016, 2018 Free Software Foundation, Inc.
+/* Copyright 2014-2023 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
@@ -13,6 +13,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#ifndef TEXT_H
+#define TEXT_H
+
typedef struct TEXT {
char *text;
size_t space;
@@ -27,3 +30,5 @@ void text_printf (TEXT *t, char *format, ...);
void text_destroy (TEXT *t);
#define text_base(t) ((t)->space ? (t)->text : (char *) 0)
+
+#endif
diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
index d72ef2c8d3..99b1e550dd 100644
--- a/tp/Texinfo/XS/xspara.c
+++ b/tp/Texinfo/XS/xspara.c
@@ -748,7 +748,7 @@ xspara__add_next (TEXT *result, char *word, int word_len,
int transparent)
}
/* Like _add_next but zero end_line_count at beginning. */
-char *
+TEXT
xspara_add_next (char *text, int text_len, int transparent)
{
static TEXT t;
@@ -757,10 +757,7 @@ xspara_add_next (char *text, int text_len, int transparent)
state.end_line_count = 0;
xspara__add_next (&t, text, text_len, transparent);
- if (t.space > 0)
- return t.text;
- else
- return "";
+ return t;
}
void
@@ -826,11 +823,10 @@ xspara_set_space_protection (int no_break,
/* Return string to be added to paragraph contents, wrapping text. This
function relies on there being a UTF-8 locale in LC_CTYPE for mbrtowc to
work correctly. */
-char *
-xspara_add_text (char *text)
+TEXT
+xspara_add_text (char *text, int len)
{
char *p = text;
- int len;
wchar_t wc;
size_t char_len;
static TEXT result;
@@ -838,7 +834,6 @@ xspara_add_text (char *text)
text_reset (&result);
- len = strlen (text); /* FIXME: Get this as an argument */
state.end_line_count = 0;
while (len > 0)
@@ -1035,10 +1030,7 @@ xspara_add_text (char *text)
}
}
- if (result.space > 0)
- return result.text;
- else
- return "";
+ return result;
}
diff --git a/tp/Texinfo/XS/xspara.h b/tp/Texinfo/XS/xspara.h
index 56f7ad706b..57520efb51 100644
--- a/tp/Texinfo/XS/xspara.h
+++ b/tp/Texinfo/XS/xspara.h
@@ -1,10 +1,12 @@
+#include "text.h"
+
int xspara_new (HV *conf);
void xspara_init_state (HV *hash);
void xspara_set_state (SV *state);
int xspara_init (int, char *);
void xspara_get_state (HV *state);
-char *xspara_add_next (char *, int, int transparent);
-char *xspara_add_text (char *);
+TEXT xspara_add_next (char *, int, int transparent);
+TEXT xspara_add_text (char *, int);
void xspara_set_space_protection (int space_protection, int ignore_columns,
int keep_end_lines, int french_spacing, int double_width_no_break);
void xspara__end_line (void);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/xspara.c (xspara_add_text, xspara_add_next): Receive length of strings as an argument and return lengths in structure. This avoids having to call strlen.,
Gavin D. Smith <=