From 95df8d27eb666820a7f76a0c4d4839735c159c94 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 19 Oct 2008 22:38:44 +0300 Subject: [PATCH] We could save some memory by not allocating new memory for every foo = 0 and foo = 1. Those are very common assignments. Signed-off-by: Dan Carpenter --- smatch_extra.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/smatch_extra.c b/smatch_extra.c index 3e0f9b77..bcb71db8 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -13,10 +13,30 @@ static int my_id; +static int _zero = 0; +static int _one = 1; + +static struct smatch_state zero = { + .name = "zero", + .data = &_zero, +}; + +static struct smatch_state one = { + .name = "one", + .data = &_one, +}; + static struct smatch_state *alloc_state(int val) { struct smatch_state *state; + if (val == 0) + return &zero; + if (val == 1) + return &one; + if (val == UNDEFINED) + return &undefined; + state = malloc(sizeof(*state)); state->name = "value"; state->data = malloc(sizeof(int)); -- 2.11.4.GIT