[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 06/08: [troff]: Slightly refactor.
From: |
G. Branden Robinson |
Subject: |
[groff] 06/08: [troff]: Slightly refactor. |
Date: |
Fri, 30 Jul 2021 01:25:04 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit a53ef998bd13598ed50bc88e06cd29c1fafe549a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Jul 30 14:41:04 2021 +1000
[troff]: Slightly refactor.
* src/roff/troff/node.cpp: Add static `image_filename_len` to store
length of cached image file name, so we don't wastefully recompute its
length every time one is re-used.
(suppress_node::tprint): Compute image file name length only
when saving a new image file name. Use saved length in later
expressions.
(min): Drop unused inline function.
---
ChangeLog | 12 ++++++++++++
src/roff/troff/node.cpp | 12 ++++--------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bf2977e..f0ebecd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2021-07-30 G. Branden Robinson <g.branden.robinson@gmail.com>
+ [troff]: Slightly refactor.
+
+ * src/roff/troff/node.cpp: Add static `image_filename_len` to
+ store length of cached image file name, so we don't wastefully
+ recompute its length every time one is re-used.
+ (suppress_node::tprint): Compute image file name length only
+ when saving a new image file name. Use saved length in later
+ expressions.
+ (min): Drop unused inline function.
+
+2021-07-30 G. Branden Robinson <g.branden.robinson@gmail.com>
+
[troff]: Fix regression (breaking important pdfmark/pdfroff
features) caused by my commit
e876d4bfd193abb9a7d1fb6e76519349bded482a, 27 July. An empty
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index f20b3ba..da72360 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -4053,13 +4053,9 @@ void suppress_node::put(troff_output_file *out, const
char *s)
static char last_position = 0;
static const char *image_filename = "";
+static size_t image_filename_len = 0;
static int subimage_counter = 0;
-inline int min(int a, int b)
-{
- return a < b ? a : b;
-}
-
/*
* tprint - if (is_on == 2)
* remember current position (l, r, c, i) and filename
@@ -4086,6 +4082,7 @@ void suppress_node::tprint(troff_output_file *out)
// remember position and filename
last_position = position;
image_filename = strsave(filename.contents());
+ image_filename_len = strlen(image_filename);
}
else {
// Now check whether the suppress node requires us to issue limits.
@@ -4108,7 +4105,7 @@ void suppress_node::tprint(troff_output_file *out)
if (0 == subimage_number)
fatal("memory allocation failure");
// Replace the %d in the filename with this number.
- size_t enough = strlen(image_filename) + 19 - format_len;
+ size_t enough = image_filename_len + 19 - format_len;
char *new_name = (char *)malloc(enough);
if (0 == new_name)
fatal("memory allocation failure");
@@ -4134,8 +4131,7 @@ void suppress_node::tprint(troff_output_file *out)
free(subimage_number);
}
else {
- const size_t len = strlen(image_filename);
- if (len > (namebuflen - 1))
+ if (image_filename_len > (namebuflen - 1))
error("file name in suppressed output escape is too long"
" (>= %1 bytes); skipping image", (int)namebuflen);
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 06/08: [troff]: Slightly refactor.,
G. Branden Robinson <=