aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <bnt period germain arrobase gmail period com>2014-01-20 17:37:50 +0100
committerBenoit Germain <bnt period germain arrobase gmail period com>2014-01-20 17:37:50 +0100
commit57ccc40847716069053a68e9d6079355dd5a1795 (patch)
tree3499458dc894502407bfda347a6fdfee7319c29b /src
parentd92a2ca2a43c68854011e2f84ce0a75802d854be (diff)
downloadlanes-57ccc40847716069053a68e9d6079355dd5a1795.tar.gz
lanes-57ccc40847716069053a68e9d6079355dd5a1795.tar.bz2
lanes-57ccc40847716069053a68e9d6079355dd5a1795.zip
linda performance improvement
slightly improve linda performance when the producer/consumer scenario leaves leave the key empty
Diffstat (limited to 'src')
-rw-r--r--src/keeper.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/keeper.c b/src/keeper.c
index b0db8b4..1a696aa 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -127,14 +127,14 @@ static void fifo_peek( lua_State* L, keeper_fifo* fifo, int count_)
127 127
128// in: fifo 128// in: fifo
129// out: remove the fifo from the stack, push as many items as required on the stack (function assumes they exist in sufficient number) 129// out: remove the fifo from the stack, push as many items as required on the stack (function assumes they exist in sufficient number)
130static void fifo_pop( lua_State* L, keeper_fifo* fifo, int _count) 130static void fifo_pop( lua_State* L, keeper_fifo* fifo, int count_)
131{ 131{
132 int fifo_idx = lua_gettop( L); // ... fifo 132 int fifo_idx = lua_gettop( L); // ... fifo
133 int i; 133 int i;
134 // each iteration pushes a value on the stack! 134 // each iteration pushes a value on the stack!
135 STACK_GROW( L, _count + 2); 135 STACK_GROW( L, count_ + 2);
136 // skip first item, we will push it last 136 // skip first item, we will push it last
137 for( i = 1; i < _count; ++ i) 137 for( i = 1; i < count_; ++ i)
138 { 138 {
139 int const at = fifo->first + i; 139 int const at = fifo->first + i;
140 // push item on the stack 140 // push item on the stack
@@ -151,8 +151,12 @@ static void fifo_pop( lua_State* L, keeper_fifo* fifo, int _count)
151 lua_rawseti( L, fifo_idx, at); // ... fifo vals val 151 lua_rawseti( L, fifo_idx, at); // ... fifo vals val
152 lua_replace( L, fifo_idx); // ... vals 152 lua_replace( L, fifo_idx); // ... vals
153 } 153 }
154 fifo->first += _count; 154 {
155 fifo->count -= _count; 155 // avoid ever-growing indexes by resetting each time we detect the fifo is empty
156 int const new_count = fifo->count - count_;
157 fifo->first = (new_count == 0) ? 1 : (fifo->first + count_);
158 fifo->count = new_count;
159 }
156} 160}
157 161
158// in: linda_ud expected at *absolute* stack slot idx 162// in: linda_ud expected at *absolute* stack slot idx