diff --git a/ChangeLog b/ChangeLog
index 272264163..416ecf114 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-09 Peter Stephenson
+
+ * Sebastian: 39875: Src/params.c, Src/string.c: add
+ dupstring_glen() to avoid redundant strlen() calls.
+
2016-11-09 Daniel Shahaf
* 39853: Completion/Unix/Command/_subversion: Accept long
diff --git a/Src/params.c b/Src/params.c
index 19a8c291d..3f0179267 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2432,8 +2432,8 @@ assignstrvalue(Value v, char *val, int flags)
char *z, *x;
int zlen;
- z = dupstring(v->pm->gsu.s->getfn(v->pm));
- zlen = strlen(z);
+ z = dupstring_glen(v->pm->gsu.s->getfn(v->pm), (unsigned*) &zlen);
+
if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
v->start--, v->end--;
if (v->start < 0) {
diff --git a/Src/string.c b/Src/string.c
index b46ea60cf..a8da14fe0 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -41,6 +41,8 @@ dupstring(const char *s)
return t;
}
+/* Duplicate string on heap when length is known */
+
/**/
mod_export char *
dupstring_wlen(const char *s, unsigned len)
@@ -54,6 +56,21 @@ dupstring_wlen(const char *s, unsigned len)
return t;
}
+/* Duplicate string on heap, returning length of string */
+
+/**/
+mod_export char *
+dupstring_glen(const char *s, unsigned *len_ret)
+{
+ char *t;
+
+ if (!s)
+ return NULL;
+ t = (char *) zhalloc((*len_ret = strlen((char *)s)) + 1);
+ strcpy(t, s);
+ return t;
+}
+
/**/
mod_export char *
ztrdup(const char *s)