message is a global static char[2048].

If I understand correctly (I've been playing with this for a while):

 * message is the user command result message displayed at the bottom
   (e.g. "Pattern not found  (press RETURN)")

 * message is initialized to all NUL bytes because it's static

 * the global static mp points to message's terminating NUL

I think we should try to drop mp. This would allow us to remove many of
the goofy homebrewed appending functions and call strlcat et al.
directly. They are currently just strlcat et al. clones that also update
mp.

Alternatives include:

 * storing message's length
 
 * just calling strlen when necessary

The strlen calls are a performance price, but message has a small max
size, is usually very small (almost all command messages are concise),
and is only updated on user interaction.

I thought I'd describe this to see if other people consider it an
improvement.

The below is a tiny first step, removing uses of mp to determine whether
message is empty.

Thoughts? ok?


Index: prompt.c
===================================================================
RCS file: /cvs/src/usr.bin/less/prompt.c,v
retrieving revision 1.20
diff -u -p -r1.20 prompt.c
--- prompt.c    13 Jan 2016 22:47:45 -0000      1.20
+++ prompt.c    13 Jan 2016 22:58:16 -0000
@@ -174,7 +174,7 @@ cond(char c, int where)
 
        switch (c) {
        case 'a':       /* Anything in the message yet? */
-               return (mp > message);
+               return (*message != '\0');
        case 'b':       /* Current byte offset known? */
                return (curr_byte(where) != -1);
        case 'c':
@@ -478,7 +478,7 @@ pr_expand(const char *proto, int maxwidt
                }
        }
 
-       if (mp == message)
+       if (*message == '\0')
                return ("");
        if (maxwidth > 0 && mp >= message + maxwidth) {
                /*

Reply via email to