Code

Define an allocator for run requests
authorJonas Fonseca <fonseca@diku.dk>
Wed, 18 Feb 2009 11:09:12 +0000 (12:09 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Wed, 18 Feb 2009 14:14:52 +0000 (15:14 +0100)
Comparing the size of the binary before and after this change, shows
that the size does not increase when -02 is used.

tig.c

diff --git a/tig.c b/tig.c
index 16b0df20aba44d1cb208d2937807810d96446617..5acb3988098720a0748b39380e778e61202bed4e 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1325,6 +1325,8 @@ struct run_request {
 static struct run_request *run_request;
 static size_t run_requests;
 
+DEFINE_ALLOCATOR(realloc_run_requests, struct run_request, 8)
+
 static enum request
 add_run_request(enum keymap keymap, int key, int argc, const char **argv)
 {
@@ -1333,11 +1335,9 @@ add_run_request(enum keymap keymap, int key, int argc, const char **argv)
        if (argc >= ARRAY_SIZE(req->argv) - 1)
                return REQ_NONE;
 
-       req = realloc(run_request, (run_requests + 1) * sizeof(*run_request));
-       if (!req)
+       if (!realloc_run_requests(&run_request, run_requests, 1))
                return REQ_NONE;
 
-       run_request = req;
        req = &run_request[run_requests];
        req->keymap = keymap;
        req->key = key;