]> git.neil.brown.name Git - edlib.git/commitdiff
doc: allow key to be passed to doc:set: in ->str2
authorNeilBrown <neil@brown.name>
Sun, 18 Jun 2023 00:03:25 +0000 (10:03 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
If "doc:set:" or "doc:append:" is called with an empty key appended to
the name, find the key in ->str2.
This avoids the need for string allocation if the key is in a variable.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c

index 77672fd7d9ae31cb47f64100e4c763fab952d4ce..e9656c1e63e9ad13a4247af227b1ef66bf32c94a 100644 (file)
@@ -480,6 +480,11 @@ DEF_CMD(doc_set)
        struct doc *d = ci->home->data;
        const char *val = ksuffix(ci, "doc:set:");
 
+       if (!*val)
+               val = ci->str2;
+       if (!val)
+               return Enoarg;
+
        if (strcmp(val, "autoclose") == 0) {
                d->autoclose = ci->num;
                return 1;
@@ -502,6 +507,11 @@ DEF_CMD(doc_append)
        const char *val = ci->str;
        const char *old;
 
+       if (!*attr)
+               attr = ci->str2;
+       if (!attr)
+               return Enoarg;
+
        if (!val || !val[0])
                return Enoarg;
        /* Append the string to the attr.  It attr doesn't