gbranden pushed a commit to branch master
in repository groff.
commit ad2acff6f74770617de30bd31f63569b2d34a079
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Jun 20 05:27:57 2026 -0500
[libgroff]: Improve `string` reallocations. (2/2)
* src/libs/libgroff/string.cpp (sfree_alloc): Avoid unnecessary
memset(3) if the new string's `len` (length) is equal to the existing
string's capacity (`oldsz`), because it is already {invariantly}
null-terminated.
---
ChangeLog | 7 +++++++
src/libs/libgroff/string.cpp | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index a7c784034..b95383240 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-06-20 G. Branden Robinson <[email protected]>
+
+ * src/libs/libgroff/string.cpp (sfree_alloc): Avoid unnecessary
+ memset(3) if the new string's `len` (length) is equal to the
+ existing string's capacity (`oldsz`), because it is already
+ {invariantly} null-terminated.
+
2026-06-20 G. Branden Robinson <[email protected]>
* src/libs/libgroff/string.cpp (srealloc): Avoid unnecessary
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index 227357b26..90cae2f01 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -74,7 +74,8 @@ static char *sfree_alloc(char *ptr, size_t oldsz, size_t len,
{
if (oldsz >= len) {
*sizep = oldsz;
- memset((ptr + len), 0, (oldsz - len));
+ if (oldsz > len)
+ memset((ptr + len), 0, (oldsz - len));
return ptr;
}
delete[] ptr;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit